core icon indicating copy to clipboard operation
core copied to clipboard

[GraphQL] Output class not respected / working for custom mutations

Open lukasluecke opened this issue 6 years ago • 6 comments

I have the following annotation in my entity:

 * @ApiResource(
 *      graphql={
 *         "custom"={
 *             "args"={},
 *             "mutation"=MyCustomResolver::class,
 *             "output"=MyCustomOutput::class
 *         }
 *     }
 * )

class DummyEntity {
    [...]
}

This should result in a GraphQL mutation customDummyEntity with empty args and a result of MyCustomOutput.

First issue which is caused by #2612 is that even though output is set the result gets wrapped in SchemaBuilder and the output class is lost during this.

After setting $useWrappedType to false: "message": "Cannot query field \"customField\" on type \"myCustomOperationPayload.customField\".",

After setting $wrapData to false: Custom mutation resolver \"App\\Resolver\\MyCustomResolver\" has to return an item of class DummyEntity but returned an item of class MyCustomOutput.

After disabling that check: "Cannot return null for non-nullable field myCustomOperationPayload.customField."

lukasluecke avatar Apr 23 '19 11:04 lukasluecke

@alanpoulain Any suggestions / ideas?

I have created a more general issue (to start a discussion) regarding custom GraphQL operations with more customizability / features #2755 - but would like to get the current implementations working correctly first.

lukasluecke avatar Apr 23 '19 11:04 lukasluecke

Is there any work around for this issue ? Also any idea when this could be fixed. I am currently hitting dead end with my project because of this issue.

sachingk avatar May 19 '21 05:05 sachingk

same here... what is even the purpose for the output param in the Mutation operation definition?

shanginn avatar Aug 04 '23 05:08 shanginn

Four years and still no solution for this ? oO Is API Platform GraphQL ready for production usage ? oO

filozofer avatar Aug 24 '23 09:08 filozofer

Still present in 2025 and 4.0 version 😟

casciotti-c avatar Mar 25 '25 14:03 casciotti-c

any ideas to fix it ? :)

soyuka avatar Mar 25 '25 17:03 soyuka