Skip to content

Commit

Permalink
fix: Improve error message for NonNull GQL types (#1333)
Browse files Browse the repository at this point in the history
* Add test adding schema with NonNull field

* Improve error message for NonNull GQL types
  • Loading branch information
AndrewSisley authored Apr 11, 2023
1 parent fe304d6 commit 1c80e10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions request/graphql/schema/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ func astTypeToKind(t ast.Type) (client.FieldKind, error) {
return client.FieldKind_FOREIGN_OBJECT, nil
}

case *ast.NonNull:
return 0, ErrNonNullNotSupported

default:
return 0, NewErrTypeNotFound(t.String())
}
Expand Down
3 changes: 3 additions & 0 deletions request/graphql/schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var (
ErrRelationMissingTypes = errors.New("relation is missing its defined types and fields")
ErrRelationInvalidType = errors.New("relation has an invalid type to be finalize")
ErrMultipleRelationPrimaries = errors.New("relation can only have a single field set as primary")
// NonNull is the literal name of the GQL type, so we have to disable the linter
//nolint:revive
ErrNonNullNotSupported = errors.New("NonNull fields are not currently supported")
)

func NewErrDuplicateField(objectName, fieldName string) error {
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/schema/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,20 @@ func TestSchemaSimpleCreatesSchemaGivenTypeWithStringField(t *testing.T) {

testUtils.ExecuteTestCase(t, []string{"users"}, test)
}

func TestSchemaSimpleErrorsGivenNonNullField(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type Users {
email: String!
}
`,
ExpectedError: "NonNull fields are not currently supported",
},
},
}

testUtils.ExecuteTestCase(t, []string{"users"}, test)
}

0 comments on commit 1c80e10

Please sign in to comment.