Skip to content

fix fragment definition directive variable handling#426

Merged
StevenACoffman merged 1 commit intovektah:masterfrom
jbellenger:fix-fragment-definition-directive-vars
Apr 30, 2026
Merged

fix fragment definition directive variable handling#426
StevenACoffman merged 1 commit intovektah:masterfrom
jbellenger:fix-fragment-definition-directive-vars

Conversation

@jbellenger
Copy link
Copy Markdown
Contributor

@jbellenger jbellenger commented Apr 29, 2026

Hi there! I'm the maintainer of graphql-conformance, which verifies spec conformance across the graphql ecosystem.

I noticed that gqlgen had some test failures that appear to originate in gqlparser.

The issue is that gqlparser does not walk directives on fragment definitions. When those directives are the only use of a variable, then those variables will be marked as unused and will incorrectly produce a validation error.

For example, in this configuration:

# schema
directive @testDirective(x: Int) on FRAGMENT_DEFINITION
type Query { placeholder: Int! }

# query
query ($x:Int) { ... F }
fragment F on Query @testDirective(x:$x) { __typename }

gqlparser produces this error:

query:2:8: Variable "$x" is never used.

This PR fixes this by walking directives of fragment definitions.

Thank you for considering this PR! I'm not familiar with this code-base or its conventions, so please feel free to point out any issue no matter how small.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 87.265% (+0.02%) from 87.245% — jbellenger:fix-fragment-definition-directive-vars into vektah:master

@jbellenger jbellenger changed the title Fix fragment definition directive variable usage fix fragment definition directive variable traversal Apr 29, 2026
@jbellenger jbellenger changed the title fix fragment definition directive variable traversal fix fragment definition directive variable handling Apr 29, 2026
@jbellenger jbellenger marked this pull request as ready for review April 29, 2026 17:22
@StevenACoffman StevenACoffman merged commit 84821cc into vektah:master Apr 30, 2026
6 checks passed
@StevenACoffman
Copy link
Copy Markdown
Collaborator

@jbellenger thanks for this! Tha validation rules in gqlparser are imported directly from the reference implementation test suite using this process: https://github.com/vektah/gqlparser/tree/master/validator/imported

I'm wondering if there's a similar way to collect and export from your repository.

@jbellenger
Copy link
Copy Markdown
Contributor Author

Hi @StevenACoffman ! This is an interesting idea. The test corpus and the system that manages it is currently in flux and I don't think it's stable enough to build on (yet).

But this use-case has been in the back of my mind for a little while -- let me think about it for a bit and then follow-up with you.

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.

3 participants