Skip to content

Bug fix and improvements to KnownDirectives - #2037

Merged
bbakerman merged 1 commit into
graphql-java:masterfrom
dugenkui03:fix_for_KnownDirectives
Sep 13, 2020
Merged

bbakerman merged 1 commit into
graphql-java:masterfrom
dugenkui03:fix_for_KnownDirectives

Conversation

@dugenkui03

Copy link
Copy Markdown
Contributor

The test below will fail:

   def sdl = '''
        
        directive @subDirective on SUBSCRIPTION
 
        type Query {
            field: String
        }
        
    '''

    def schema = TestUtil.schema(sdl)


    def "valid  directive on SUBSCRIPTION"() {
        def spec = '''
            subscription sub @subDirective{
                field 
            }
        '''

        when:
        def document = TestUtil.parseQuery(spec)
        def validator = new Validator();
        def validationErrors = validator.validateDocument(schema, document);

        then:
        validationErrors.size() == 0
    }

Error message:

    Condition not satisfied:

    validationErrors.size() == 0
    |                |      |
    |                1      false
    [ValidationError{validationErrorType=MisplacedDirective, queryPath=null, message=Validation error of type MisplacedDirective: Directive subDirective not allowed here, locations=[SourceLocation{line=2, column=30}], description='Directive subDirective not allowed here'}]

    Condition not satisfied:

    validationErrors.size() == 0
    |                |      |
    |                1      false
    [ValidationError{validationErrorType=MisplacedDirective, queryPath=null, message=Validation error of type MisplacedDirective: Directive subDirective not allowed here, locations=[SourceLocation{line=2, column=30}], description='Directive subDirective not allowed here'}]

    at graphql.validation.rules.KnownDirectivesTest.valid  directive on SUBSCRIPTION(KnownDirectivesTest.groovy:265)

There are two main change to KnownDirectives.hasInvalidLocation in this PR:

  1. Determain whether directive's ancestor is SUBSCRIPTION, and then determain whether definitionLocations contain SUBSCRIPTION;
  2. Invoking directive.validLocations() ahead, and then determain whether definitionLocations contain usageLocation. since directive.validLocations() will do copy operation, details in ExecutionStepInfo optimisations #2023 .

@bbakerman bbakerman added this to the 16.0 milestone Sep 13, 2020
@bbakerman
bbakerman merged commit 7fc94c5 into graphql-java:master Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants