Skip to content

Commit

Permalink
Add test case for nullable field
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmeek committed Mar 7, 2021
1 parent 469e31b commit 1fac78e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 1 deletion.
91 changes: 91 additions & 0 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,6 +1,7 @@
extend type Query {
errorBubble: Error
errorBubbleList: [Error!]
errorList: [Error]
errors: Errors
valid: String!
}
Expand Down
18 changes: 17 additions & 1 deletion codegen/testserver/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func TestNullBubbling(t *testing.T) {
resolvers.QueryResolver.ErrorBubbleList = func(ctx context.Context) (i []*Error, e error) {
return []*Error{nil}, nil
}
resolvers.QueryResolver.ErrorList = 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 @@ -70,6 +73,19 @@ func TestNullBubbling(t *testing.T) {
require.Equal(t, "Ok", resp.Valid)
})

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

require.Nil(t, err)
require.Equal(t, len(resp.ErrorList), 1)
require.Nil(t, resp.ErrorList[0])
require.Equal(t, "Ok", resp.Valid)
})

t.Run("when non-null list element is null", func(t *testing.T) {
var resp struct {
Valid string
Expand Down Expand Up @@ -104,7 +120,7 @@ func TestNullBubbling(t *testing.T) {
resolvers.ErrorsResolver.D = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil }
resolvers.ErrorsResolver.E = func(ctx context.Context, obj *Errors) (i *Error, e error) { return nil, nil }

err := c.Post(`{ errors {
err := c.Post(`{ errors {
a { id },
b { id },
c { id },
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func (r *queryResolver) ErrorBubbleList(ctx context.Context) ([]*Error, error) {
panic("not implemented")
}

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

func (r *queryResolver) Errors(ctx context.Context) (*Errors, error) {
panic("not implemented")
}
Expand Down
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 1fac78e

Please sign in to comment.