Skip to content

Reject @skip and @include in operations - #143

Closed
spawnia wants to merge 2 commits into
masterfrom
reject-client-directives
Closed

spawnia wants to merge 2 commits into
masterfrom
reject-client-directives

Conversation

@spawnia

@spawnia spawnia commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Part of #149

Operations with @skip or @include generate non-null types, and the result throws InvalidDataException: Missing field when the server omits a field.
This makes codegen fail instead, naming the operation, directive and location, and saying Sailor does not support client directives.

Before and after

Before: query Foo($v: Boolean!) { bar @skip(if: $v) } generates Foo with a non-null bar. A skipped field throws at runtime.

After: codegen throws Sailor does not support client directives, found @skip on field bar in operation Foo in <path>.
The check covers fields, inline fragments and fragment spreads, in operations and in fragment definitions (named as fragment X).
It lives in Validator::validateDocuments(), before fragments are folded.

All uses are rejected, including literal ones such as `@skip(if: false)`

Telling literal arguments apart from variables needs extra code for a case nobody should write.

Example and docs changes

examples/simple/src/clientDirectives.graphql used all three locations, so I deleted it with its generated files in expected/.
The README gets a "Client directives" section, and the changelog lists this under Changed.
FoldFragments still copies spread directives onto inlined fragments. That code is now unreachable, and I left it untouched.

Size: 41 added lines in `src`
 src/Codegen/Validator.php | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Alternatives: #79 (full support), #148 (full support on the merged field model), #146 (fields only)

🤖 Generated with Claude Code

Codegen fails with the operation, directive and location instead of
generating non-null types that throw at runtime when the server omits a field.
Remove the client directive operations from the simple example.

🤖 Generated with Claude Code
🤖 Generated with Claude Code
@spawnia

spawnia commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

🤖 Superseded by #148, which supports the directives instead of rejecting them.

@spawnia spawnia closed this Oct 6, 2026
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.

1 participant