Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created August 4, 2020 22:00
Show Gist options
  • Save betweenbrain/6b3a2397a7bcfef12e8e0c82ad5ac55d to your computer and use it in GitHub Desktop.
Save betweenbrain/6b3a2397a7bcfef12e8e0c82ad5ac55d to your computer and use it in GitHub Desktop.
WP GraphQL register interface and to types
<?php
/**
* From https://wp-graphql.slack.com/archives/C3NM1M291/p1592854006371300?thread_ts=1592852289.366600&cid=C3NM1M291
*/
add_action( 'graphql_register_types', function() {
register_graphql_interface_type( 'MyNewInterface', [
'fields' => [
'myNewField' => [
'type' => 'String',
'resolve' => function() {
return 'resolve data...';
}
],
],
] );
register_graphql_interfaces_to_types( [ 'MyNewInterface' ], [ 'Post' ] );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment