Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman A. Grigorovich committed Mar 6, 2023
1 parent a544ab0 commit 1146d1e
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 12 deletions.
3 changes: 2 additions & 1 deletion codegen/testserver/followschema/nulls.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ extend type Query {
errorList: [Error]
errors: Errors
valid: String!
invalid: String!
}

extend type Subscription {
errorRequired: Error!
errorRequired: Error!
}

type Errors {
Expand Down
12 changes: 12 additions & 0 deletions codegen/testserver/followschema/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package followschema

import (
"context"
"errors"
"testing"

"github.com/99designs/gqlgen/client"
Expand All @@ -14,6 +15,9 @@ func TestNullBubbling(t *testing.T) {
resolvers.QueryResolver.Valid = func(ctx context.Context) (s string, e error) {
return "Ok", nil
}
resolvers.QueryResolver.Invalid = func(ctx context.Context) (s string, e error) {
return "Ok", errors.New("ERROR")
}
resolvers.QueryResolver.Errors = func(ctx context.Context) (errors *Errors, e error) {
return &Errors{}, nil
}
Expand Down Expand Up @@ -132,4 +136,12 @@ func TestNullBubbling(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "the requested element is null which the schema does not allow")
})

t.Run("when non-nullable field returns content while error occured", func(t *testing.T) {
var resp any
err := c.Post(`query { invalid }`, &resp)
require.Nil(t, resp)
require.NotNil(t, err)
require.Contains(t, err.Error(), `{"message":"ERROR","path":["invalid"]}`)
})
}
5 changes: 5 additions & 0 deletions codegen/testserver/followschema/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func (r *queryResolver) Valid(ctx context.Context) (string, error) {
panic("not implemented")
}

// // foo
func (r *queryResolver) Invalid(ctx context.Context) (string, error) {
panic("not implemented")
}

// // foo
func (r *queryResolver) Panics(ctx context.Context) (*Panics, error) {
panic("not implemented")
Expand Down
8 changes: 8 additions & 0 deletions codegen/testserver/followschema/root_.generated.go

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

65 changes: 65 additions & 0 deletions codegen/testserver/followschema/schema.generated.go

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

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

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

73 changes: 73 additions & 0 deletions codegen/testserver/singlefile/generated.go

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

3 changes: 2 additions & 1 deletion codegen/testserver/singlefile/nulls.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ extend type Query {
errorList: [Error]
errors: Errors
valid: String!
invalid: String!
}

extend type Subscription {
errorRequired: Error!
errorRequired: Error!
}

type Errors {
Expand Down
12 changes: 12 additions & 0 deletions codegen/testserver/singlefile/nulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package singlefile

import (
"context"
"errors"
"testing"

"github.com/99designs/gqlgen/client"
Expand All @@ -14,6 +15,9 @@ func TestNullBubbling(t *testing.T) {
resolvers.QueryResolver.Valid = func(ctx context.Context) (s string, e error) {
return "Ok", nil
}
resolvers.QueryResolver.Invalid = func(ctx context.Context) (s string, e error) {
return "Ok", errors.New("ERROR")
}
resolvers.QueryResolver.Errors = func(ctx context.Context) (errors *Errors, e error) {
return &Errors{}, nil
}
Expand Down Expand Up @@ -132,4 +136,12 @@ func TestNullBubbling(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "the requested element is null which the schema does not allow")
})

t.Run("when non-nullable field returns content while error occured", func(t *testing.T) {
var resp any
err := c.Post(`query { invalid }`, &resp)
require.Nil(t, resp)
require.NotNil(t, err)
require.Contains(t, err.Error(), `{"message":"ERROR","path":["invalid"]}`)
})
}
5 changes: 5 additions & 0 deletions codegen/testserver/singlefile/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func (r *queryResolver) Valid(ctx context.Context) (string, error) {
panic("not implemented")
}

// // foo
func (r *queryResolver) Invalid(ctx context.Context) (string, error) {
panic("not implemented")
}

// // foo
func (r *queryResolver) Panics(ctx context.Context) (*Panics, error) {
panic("not implemented")
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/singlefile/stub.go

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

8 changes: 3 additions & 5 deletions plugin/resolvergen/testdata/filetemplate/out/schema.custom.go

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

Loading

0 comments on commit 1146d1e

Please sign in to comment.