Skip to content

Commit

Permalink
check for non enum values on validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ameyarao98 committed Jun 25, 2022
1 parent 0e3e4c2 commit dd63349
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ func validateDefinition(schema *Schema, def *Definition) *gqlerror.Error {
if len(def.EnumValues) == 0 {
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more unique enum values.", def.Kind, def.Name)
}
for _, value := range def.EnumValues {
for _, nonEnum := range [3]string{"true", "false", "null"} {
if value.Name == nonEnum {
return gqlerror.ErrorPosf(def.Position, "%s %s: non-enum value %s.", def.Kind, def.Name, value.Name)
}
}
}
case InputObject:
if len(def.Fields) == 0 {
return gqlerror.ErrorPosf(def.Position, "%s %s: must define one or more input fields.", def.Kind, def.Name)
Expand Down
8 changes: 8 additions & 0 deletions validator/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,11 @@ type references:
error:
message: "Undefined type FooBar."
locations: [{line: 1, column: 21}]

- name: Invalid enum value
input: |
enum Enum { true }
error:
message: "ENUM Enum: non-enum value true."
locations: [{line: 1, column: 6}]

0 comments on commit dd63349

Please sign in to comment.