feat: Add directive layer#807
Open
michael-georgiadis wants to merge 6 commits into
Open
Conversation
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.
Description
As per your comment on this PR, I am splitting the implementation into two.
I am focusing on configuring the directive layer on this one. Specifying two directives to start with.
How it works
A directive is a PHP attribute implementing one of the family interfaces, which ties it to a GraphQL location (
FieldDirective→FIELD_DEFINITION,InputObjectTypeDirective→INPUT_OBJECT, etc.). Implementing the marker interface alone is metadata-only; implementing the matchingBehavioral*sub-interface adds an apply hook that runs through a middleware pipe during type generation.The built-ins on the layer
#[OneOf]→ sets webonyx'sisOneOfflag → printsinput LookupInput @oneOf.#[Deprecated(reason:)]→ sets the field's deprecation reason → printslegacy: String! @deprecated(reason: "...").Both bind to directives webonyx already declares, so they print through webonyx's own SDL output and we don't register duplicate definitions for them (
DirectiveDefinition::$builtIn).@deprecated: additive, not a rewriteThe existing docblock
@deprecatedsupport is untouched.#[Deprecated]is an attribute-basedpath that composes with it rather than fighting it:
#[Deprecated(reason: 'X')](± docblock)@deprecated(reason: "X")— explicit wins#[Deprecated]+/** @deprecated Y */@deprecated(reason: "Y")— docblock kept#[Deprecated], no docblock@deprecated(reason: "No longer supported")— defaultUsage validation
PHP's
#[Attribute]targets can't tell a#[Type]class from an#[Input]class (both areTARGET_CLASS), so a misplaced#[OneOf]on a#[Type]would otherwise be silently dropped by the interface-based collection.DirectiveValidatorcatches that and throws a clearInvalidDirectiveExceptioninstead.