Reject directives applied at the wrong location, without a required argument or twice in 15.0.0 · Issue #884 · graphql-java-kickstart/graphql-java-tools · GitHub
Skip to content

Reject directives applied at the wrong location, without a required argument or twice in 15.0.0 #884

Open

Description

@oryan-block

Since #225, tools logs a warning when a schema applies a directive in a way its definition doesn't allow, and still builds the schema:

directive @uppercase on OBJECT
directive @auth(role: String!) on FIELD_DEFINITION
directive @cached(ttl: Int) on FIELD_DEFINITION

type Query {
    motto: String @uppercase
    secret: String @auth
    members: [Member!] @cached @cached(ttl: 10)
}

Directive @uppercase is applied to field 'Query.motto', but it's declared on OBJECT, not FIELD_DEFINITION.
Directive @auth is applied to field 'Query.secret' without its required argument 'role'.
Directive @cached isn't repeatable but is applied more than once to field 'Query.members'.

graphql-java's SchemaGenerator rejects all three, and the spec doesn't allow them either. But they always built with tools, so failing on them has to wait for a major release.

What to change

  • replace the warnings from SchemaParser#directiveProblems with a SchemaError that has the same messages
  • probably do the same for the warning in SchemaParser#directivesOf, when a type extension applies a non-repeatable directive the type already has. It's the same mistake, it just drops the repeat today
  • turn DirectiveTest.should warn about invalid applied directives and keep them into a test for the error
  • mention it in the 15.0.0 release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions