Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Created March 6, 2023 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbahl/dcbe929ccc98804f33254412138728c4 to your computer and use it in GitHub Desktop.
Save jasonbahl/dcbe929ccc98804f33254412138728c4 to your computer and use it in GitHub Desktop.
testing registering a connection to an interface that other interfaces implement
add_action( 'graphql_register_types', function() {
register_graphql_field( 'RootQuery', 'testType', [
'type' => 'TestType',
'resolve' => function() {
return [
'__typename' => 'TestType',
'test' => 'Test Field Value...',
'id' => 'root:testType:1'
];
}
] );
register_graphql_interface_type( 'TestInterfaceB', [
'description' => 'Test Interface B',
'fields' => [
'interfaceBTestField' => [
'type' => 'String',
'description' => 'Test Field defined on the TestInterfaceB',
],
],
]);
register_graphql_interface_type( 'TestInterface', [
'description' => 'Test Interface',
'interfaces' => [ 'TestInterfaceB' ],
'fields' => [
'interfaceTestField' => [
'type' => 'String',
'description' => 'Test Field defined on the TestInterface',
],
],
]);
register_graphql_object_type( 'TestType', [
'interfaces' => [ 'TestInterface', 'Node' ],
'description' => 'Test type',
'fields' => [
'test' => [
'type' => 'String',
'description' => 'Test Field',
],
],
] );
register_graphql_connection([
'fromType' => 'TestInterfaceB',
'toType' => 'TestType',
'fromFieldName' => 'testInterfaceBToTestTypeConnection',
'resolve' => function() {
return [
'nodes' => [
[
'__typename' => 'TestType',
'id' => 'test:id:1',
'test' => 'test value',
'interfaceTestField' => 'interface test value'
],
[
'__typename' => 'TestType',
'id' => 'test:id:2',
'test' => 'test value',
'interfaceTestField' => 'interface test value'
]
]
];
}
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment