Skip to content

How to resolve WP Post Object by custom mutation ? #2702

Answered by justlevine
jiwon-mun asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @jiwon-mun ,

That's because you need to return a WPGraphQL Post model and not the WP_Post object.

Changing your return statement in $config['outputFields']['post']['resolve'] to the following should fix your issue:

- return isset( $payload['post'] ) ? $payload['post'] : null;
+ return isset( $payload['post'] ) ? new \WPGraphQL\Model\Post( $payload['post'] ) : null;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jiwon-mun
Comment options

Answer selected by jiwon-mun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants