Skip to content

fix: support #[Type] interfaces used as output types#817

Merged
oojacoboo merged 2 commits into
thecodingmachine:masterfrom
michael-georgiadis:fix/type-annotated-interface-as-output-type
Jul 16, 2026
Merged

fix: support #[Type] interfaces used as output types#817
oojacoboo merged 2 commits into
thecodingmachine:masterfrom
michael-georgiadis:fix/type-annotated-interface-as-output-type

Conversation

@michael-georgiadis

@michael-georgiadis michael-georgiadis commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Closes #816

Description

#[Type] on a PHP interface is documented as a supported way to declare a GraphQL interface, but if that interface is used as an output type, building the schema blows up:

Expected GraphQL type "X" to be an MutableObjectType. 
Got a TheCodingMachine\GraphQLite\Types\TypeAnnotatedInterfaceType

It only shows up once the interface has already been registered (e.g. it was referenced by name via an outputType before the full type map is built), so it tends to surface on $schema->assertValid() rather than on a narrow query.

This was happening, because getOutputTypes() calls the object-only mapClassToType() on every supported class, interfaces included. Its "already registered" branch then calls getMutableObjectType(), which throws on an interface.

Fix

When the mapped type is a MutableInterfaceType, return its generated concrete companion instead (same conversion the method already does on the non-cached path).

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.71%. Comparing base (53f9d49) to head (bf2afa4).
⚠️ Report is 161 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #817      +/-   ##
============================================
- Coverage     95.72%   91.71%   -4.02%     
- Complexity     1773     2023     +250     
============================================
  Files           154      198      +44     
  Lines          4586     5432     +846     
============================================
+ Hits           4390     4982     +592     
- Misses          196      450     +254     

☔ 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.

@oojacoboo

Copy link
Copy Markdown
Collaborator

@michael-georgiadis thanks for this!

@oojacoboo oojacoboo merged commit c0727c1 into thecodingmachine:master Jul 16, 2026
13 checks passed
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.

#[Type] interface used as an output type breaks schema build on 8.3.0 (worked on 8.1.2)

3 participants