Skip to content

fix(graphql): honor custom mutation output class in payload type#8300

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/graphql-custom-mutation-output-2754
Open

fix(graphql): honor custom mutation output class in payload type#8300
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/graphql-custom-mutation-output-2754

Conversation

@soyuka

@soyuka soyuka commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

A custom GraphQL mutation declaring its own output class did not expose that class on its payload type. When the mutation and query normalization contexts matched, TypeBuilder reused the item_query type for the wrapped payload (to allow client cache sharing), so the payload exposed the resource fields instead of the output DTO — producing the reported Cannot query field "X" on type "...". The fix forces a dedicated wrapped type whenever the mutation's output class differs from the query operation's output class.

Reproduction

A resource with a custom Mutation(resolver: ..., output: SumResult::class) whose output DTO has different fields than the resource: before the fix, querying the DTO's fields on the mutation payload fails; the payload carries the resource's fields.

Test plan

  • Added failing functional test (tests/Functional/GraphQl/Issue2754Test.php) covering the bug.
  • Test passes after the fix.
  • Full GraphQl functional suite + TypeBuilder/introspection/schema-export tests still pass locally.

Fixes #2754

A custom GraphQL mutation declaring its own output class reused the item_query
type for its wrapped payload when normalization contexts matched, exposing the
resource fields instead of the output DTO. Force a dedicated wrapped type when
the mutation output class differs from the query output class.

Fixes api-platform#2754
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