Skip to content

Commit

Permalink
Add Test Case
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmeek committed Mar 6, 2021
1 parent 0b5da15 commit 635b1ae
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 9 deletions.
105 changes: 101 additions & 4 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codegen/testserver/nulls.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extend type Query {
errorBubble: Error
errorBubbleList: [Error!]
errors: Errors
valid: String!
}
Expand Down
16 changes: 15 additions & 1 deletion codegen/testserver/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ func TestNullBubbling(t *testing.T) {
resolvers.QueryResolver.Valid = func(ctx context.Context) (s string, e error) {
return "Ok", nil
}

resolvers.QueryResolver.Errors = func(ctx context.Context) (errors *Errors, e error) {
return &Errors{}, nil
}
resolvers.QueryResolver.ErrorBubble = func(ctx context.Context) (i *Error, e error) {
return &Error{ID: "E1234"}, nil
}
resolvers.QueryResolver.ErrorBubbleList = func(ctx context.Context) (i []*Error, e error) {
return []*Error{nil}, nil
}

c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})))

Expand Down Expand Up @@ -68,6 +70,18 @@ func TestNullBubbling(t *testing.T) {
require.Equal(t, "Ok", resp.Valid)
})

t.Run("when non-null list element is null", func(t *testing.T) {
var resp struct {
Valid string
ErrorBubbleList []*struct{}
}
err := c.Post(`query { valid, errorBubbleList { id } }`, &resp)

require.EqualError(t, err, `[{"message":"must not be null","path":["errorBubbleList", 0]}]`)
require.Nil(t, resp.ErrorBubbleList)
require.Equal(t, "Ok", resp.Valid)
})

t.Run("null args", func(t *testing.T) {
var resp struct {
NullableArg *string
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func (r *queryResolver) ErrorBubble(ctx context.Context) (*Error, error) {
panic("not implemented")
}

func (r *queryResolver) ErrorBubbleList(ctx context.Context) ([]*Error, error) {
panic("not implemented")
}

func (r *queryResolver) Errors(ctx context.Context) (*Errors, error) {
panic("not implemented")
}
Expand Down
8 changes: 4 additions & 4 deletions codegen/testserver/slices.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ extend type Query {
}

type Slices {
test1: [String]
test2: [String!]
test3: [String]!
test4: [String!]!
test1: [String]
test2: [String!]
test3: [String]!
test4: [String!]!
}

scalar Bytes
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 635b1ae

Please sign in to comment.