Created
March 6, 2023 19:18
-
-
Save jasonbahl/dcbe929ccc98804f33254412138728c4 to your computer and use it in GitHub Desktop.
testing registering a connection to an interface that other interfaces implement
This file contains 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_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