Skip to content

feat: Add directive layer#807

Open
michael-georgiadis wants to merge 8 commits into
thecodingmachine:masterfrom
michael-georgiadis:feat/graphql-directive-layer
Open

feat: Add directive layer#807
michael-georgiadis wants to merge 8 commits into
thecodingmachine:masterfrom
michael-georgiadis:feat/graphql-directive-layer

Conversation

@michael-georgiadis

Copy link
Copy Markdown

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 (FieldDirectiveFIELD_DEFINITION, InputObjectTypeDirectiveINPUT_OBJECT, etc.). Implementing the marker interface alone is metadata-only; implementing the matching Behavioral* sub-interface adds an apply hook that runs through a middleware pipe during type generation.

The built-ins on the layer

  • #[OneOf] → sets webonyx's isOneOf flag → prints input LookupInput @oneOf.
  • #[Deprecated(reason:)] → sets the field's deprecation reason → prints
    legacy: 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 rewrite

The existing docblock @deprecated support is untouched. #[Deprecated] is an attribute-based
path that composes with it rather than fighting it:

Declaration Result
#[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") — default

Usage validation

PHP's #[Attribute] targets can't tell a #[Type] class from an #[Input] class (both are TARGET_CLASS), so a misplaced #[OneOf] on a #[Type] would otherwise be silently dropped by the interface-based collection. DirectiveValidator catches that and throws a clear InvalidDirectiveException instead.

@michael-georgiadis michael-georgiadis changed the title Feat/graphql directive layer feat: Add directive layer Jun 2, 2026
@michael-georgiadis

Copy link
Copy Markdown
Author

Hey @oojacoboo, I don't want this to become stale. Is it something that you need to get it over the finish line?

@oojacoboo

Copy link
Copy Markdown
Collaborator

Well, for starters, the tests are all going to have to pass. Beyond that, an hour of my time to review it.

@andrew-demb

Copy link
Copy Markdown
Contributor

Well, for starters, the tests are all going to have to pass.

see #811

@oojacoboo

Copy link
Copy Markdown
Collaborator

@michael-georgiadis #811 was merged. Please rebase and hopefully that resolves tests.

@codecov-commenter

codecov-commenter commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.02715% with 159 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.36%. Comparing base (53f9d49) to head (c99f87f).
⚠️ Report is 156 commits behind head on master.

Files with missing lines Patch % Lines
...irectives/Exceptions/InvalidDirectiveException.php 25.00% 48 Missing ⚠️
src/Middlewares/DirectiveInputFieldMiddleware.php 28.00% 18 Missing ⚠️
src/Middlewares/DirectiveObjectTypeMiddleware.php 5.26% 18 Missing ⚠️
src/Directives/DirectiveAstBuilder.php 71.15% 15 Missing ⚠️
src/Directives/DirectiveResolver.php 79.10% 14 Missing ⚠️
src/Directives/DirectiveLocation.php 0.00% 9 Missing ⚠️
src/ObjectTypeDescriptor.php 0.00% 9 Missing ⚠️
src/Middlewares/ObjectTypeNext.php 0.00% 7 Missing ⚠️
src/TypeGenerator.php 33.33% 6 Missing ⚠️
src/InputObjectTypeDescriptor.php 55.55% 4 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #807      +/-   ##
============================================
- Coverage     95.72%   92.36%   -3.36%     
- Complexity     1773     2019     +246     
============================================
  Files           154      198      +44     
  Lines          4586     5424     +838     
============================================
+ Hits           4390     5010     +620     
- Misses          196      414     +218     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@michael-georgiadis

Copy link
Copy Markdown
Author

@oojacoboo Done ✅ !

I think the most meaningful cases are covered and I also included an end-to-end one. However, if you want more coverage on specific sub-units happy to add more 🫡

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.

4 participants