Repository navigation
fix: refuse directives that can never be applied, and correct directive docblocks - #854
Merged
oojacoboo merged 2 commits intoDec 1, 2026
Conversation
Only FIELD_DEFINITION, INPUT_FIELD_DEFINITION, OBJECT and INPUT_OBJECT have an apply path. A custom directive declaring any other location (executable or type-system), or no location, was registered and published in the schema but never applied. InterfaceLocationValidator now refuses it with InvalidDirectiveException::unsupportedLocations() or ::noLocations(). builtIn: true directives are exempt, since webonyx owns their definition. Also correct docblocks and docs that overstated what directives do: - a behavioral field or input field directive runs last at build time, so its withResolver() wrapper is outermost at request time and runs before the #[Logged], #[Right] and #[Security] checks; - applied directives live on astNode->directives only; introspection and SchemaPrinter expose the definitions, not the applications; - DirectiveDefinition pointed to a nonexistent DirectiveValidator method.
A builtIn: true directive skipped the location rule on trust: any name, with any or no locations, registered without publishing a definition and was never applied. InterfaceLocationValidator now requires its name to be a webonyx built-in (InvalidDirectiveException::unknownBuiltIn()), its locations to be among webonyx's for that name (::locationsOutsideBuiltIn()), and at least one location GraphQLite applies (::noLocations() or ::unsupportedLocations()). That last rule also rules out @Skip, @include and @specifiedBy, so their reserved-name message no longer suggests builtIn: true. Docs: applied @deprecated and @OneOf do show in introspection and printed SDL; the FailWith fallback applies to fields, not input fields; the location rule is part of the custom directives changelog entry.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #854 +/- ##
============================================
- Coverage 95.72% 94.62% -1.11%
- Complexity 1773 2217 +444
============================================
Files 154 208 +54
Lines 4586 5913 +1327
============================================
+ Hits 4390 5595 +1205
- Misses 196 318 +122 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #815 (custom directives). It closes two ways a directive could register and then silently do nothing, and corrects docblocks and docs that describe behavior the code does not have.
Validation
Only
FIELD_DEFINITION,INPUT_FIELD_DEFINITION,OBJECTandINPUT_OBJECThave an apply path.InvalidDirectiveExceptionnaming the class, the offending locations and the supported ones.directives.mdalready said executable directives cannot be defined; nothing enforced it.builtIn: truedirective skipped every location and name check, so any class could set it with a made-up name and register with no definition and no effect. It must now name a directive webonyx defines, declare only locations in webonyx's definition of it, and include at least one location GraphQLite applies. That also rules outbuiltIn: trueoverrides of@skip,@includeand@specifiedBy, so their reserved-name message no longer suggests it.The bundled
#[Deprecated]and#[OneOf], and a user override of either, keep working. No existing test changed.Docblocks and docs
BehavioralFieldDirectivesaid its hook is chained ahead of the field pipe.SchemaFactorypipes the directive middleware last, after the user, security, authorization and cost middlewares. So the hook runs after them at build time, and a resolver installed withwithResolver()is the outermost wrapper at request time: code before the wrapped call runs before the#[Logged],#[Right]and#[Security]checks. The same holds for input fields.directives.mdnow describes both phases, and notes that the#[FailWith]fallback applies to fields only.DirectiveAstBuilderand the four directive middlewares said applied directives show up in printed SDL. They live onastNode->directivesonly; introspection and webonyx'sSchemaPrinterexpose a custom directive's definition, not its applications (checked at webonyx 15.38.3 and 15.43.0).@deprecatedand@oneOfshow through the type's own properties.DirectiveDefinitionpointed to aDirectiveValidator::isRepeatable()that does not exist; it isDirectiveResolver::isRepeatable().Checks
phpunit,composer phpstanandcomposer cs-checkpass on PHP 8.2, 8.3, 8.4 and 8.5, withcomposer updateandcomposer update --prefer-lowest(781 tests).