Last active
June 4, 2020 13:51
-
-
Save jasonbahl/ab36ff6a4a54c904c795643810b23afe to your computer and use it in GitHub Desktop.
Showing how to register a connection to attached media in WPGraphQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'graphql_register_types', function() { | |
register_graphql_connection([ | |
'fromType' => 'ContentNode', | |
'toType' => 'MediaItem', | |
'fromFieldName' => 'attachedMedia', | |
'connectionArgs' => \WPGraphQL\Connection\PostObjects::get_connection_args(), | |
'resolve' => function( \WPGraphQL\Model\Post $source, $args, $context, $info ) { | |
$resolver = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $source, $args, $context, $info, 'attachment' ); | |
$resolver->setQueryArg( 'post_parent', $source->ID ); | |
return $resolver->get_connection(); | |
} | |
]); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment