-
Notifications
You must be signed in to change notification settings - Fork 8
GraphQL service does not support interfaces #33
Description
As far as I can see – and I tried and played with this for a couple of hours – interfaces are not yet supported.
My concrete use case is implementing the server specification for Relay, which enables me to provide cursor-based pagination and universal object identification.
Given the following minimal GraphQL schema:
interface Node {
id: ID!
}
type CustomerAccount implements Node {
id: ID!
customerName: String!
}
type Query {
node(
id: ID!
): Node
}resolveType
When I submit any query, I will receive an exception:
Type "Node" is missing a "__resolveType" resolver.
Pass false into "resolverValidationOptions.requireResolversForResolveType" to disable this warning.
GraphQLTools\Generate\SchemaError
Packages/Libraries/t3n/graphql-tools/src/Generate/CheckForResolveTypeResolver.php 34
Just for good measure, I tried setting that validation option to false, but there is currently no way to do that in the Flow package (it is possible programmatically in the GraphQLTools package).
To fix this, we need a way to provide a custom resolveType function. Ideally, Flow would automatically recognize such a function in my Resolver class.
internal error in response
I temporarily solved the first problem by hardcoding the resolve type as follows:
namespace GraphQLTools\Generate;
…
class CheckForResolveTypeResolver
{
/**
* @throws SchemaError
*/
public static function invoke(Schema $schema, ?bool $requireResolversForResolveType = null) : void
{
/**
* @var UnionType|InterfaceType $typeName
*/
foreach ($schema->getTypeMap() as $typeName => $type) {
if (! ($type instanceof UnionType || $type instanceof InterfaceType)) {
continue;
}
if (!isset($type->config['resolveType'])) {
$type->config['resolveType'] = function () {
return 'CustomerAccount';
};
}
…
}
}
}Now the schema warning is gone.
When I try to query a node as follows:
query Query {
node(id: "1234") {
id
}
}I receive a inexpressive error:
{
"errors":
[
{"message":"Internal server error",
"extensions":
{"category":"internal"},
"locations":[
{"line":2,"column":5}
],
"path":["node"]}
],
"data":{"node":null}
}In the resolver, I tried solving the issue by returning different kinds of data. Among them, a CustomerAccount class (which supports JsonSerialize), an array based on CustomerAccount, a literal, an array with just an id:
/**
* @param $_
* @param array $arguments
*/
public function node($_, array $arguments)
{
return [
'id' => '1234'
];
}I'm a bit clueless about what the correct data would be to return in the query function.