Routes
Last updated
Was this helpful?
Was this helpful?
use GraphQL\Error\Error;
...
/**
* {@inheritdoc}
*/
protected function getResolverRegistry() {
...
// Tell GraphQL how to resolve types of a common interface.
$registry->addTypeResolver('NodeInterface', function ($value) {
if ($value instanceof NodeInterface) {
switch ($value->bundle()) {
case 'article': return 'Article';
case 'page': return 'Page';
}
}
throw new Error('Could not resolve content type.');
});
$registry->addFieldResolver('Query', 'route', $builder->compose(
$builder->produce('route_load')
->map('path', $builder->fromArgument('path')),
$builder->produce('route_entity')
->map('url', $builder->fromParent())
));
...
return $registry;
}query {
route(path: "/node/1") {
... on Article {
id
title
}
}
}{
"data": {
"route": {
"id": 1,
"title": "Hello GraphQL"
}
}
}