Skip to content

Commit

Permalink
Validate enum values directive are legit (#257)
Browse files Browse the repository at this point in the history
* validate enum values directive is legit

* Add tests
  • Loading branch information
fredzqm committed Jun 10, 2023
1 parent 761b8f0 commit b74a952
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func validateDefinition(schema *Schema, def *Definition) *gqlerror.Error {
return gqlerror.ErrorPosf(def.Position, "%s %s: non-enum value %s.", def.Kind, def.Name, value.Name)
}
}
if err := validateDirectives(schema, value.Directives, LocationEnumValue, nil); err != nil {
return err
}
}
case InputObject:
if len(def.Fields) == 0 {
Expand Down
20 changes: 19 additions & 1 deletion validator/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,16 @@ directives:
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
- name: must be declared
- name: must be declared (type)
input: |
type User @foo {
name: String
}
error:
message: "Undefined directive foo."
locations: [{line: 1, column: 12}]

- name: must be declared (field)
input: |
type User {
name: String @foo
Expand All @@ -537,6 +546,15 @@ directives:
message: "Undefined directive foo."
locations: [{line: 2, column: 17}]

- name: must be declared (enum)
input: |
enum Unit {
METER @foo
}
error:
message: "Undefined directive foo."
locations: [{line: 2, column: 10}]

- name: cannot be self-referential
input: |
directive @A(foo: Int! @A) on FIELD_DEFINITION
Expand Down

0 comments on commit b74a952

Please sign in to comment.