Custom schemas
Clone the SdlSchemaTest
namespace Drupal\mydrupalgql\Plugin\GraphQL\Schema;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\graphql\GraphQL\ResolverBuilder;
use Drupal\graphql\GraphQL\ResolverRegistry;
use Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase;
/**
* @Schema(
* id = "mydrupalgql",
* name = "My Drupal Graphql schema"
* )
* @codeCoverageIgnore
*/
class SdlSchemaMyDrupalGql extends SdlSchemaPluginBase {
/**
* {@inheritdoc}
*/
protected function getSchemaDefinition() {
return <<<GQL
schema {
query: Query
}
type Query {
article(id: Int!): Article
page(id: Int!): Page
node(id: Int!): NodeInterface
label(id: Int!): String
}
type Article implements NodeInterface {
id: Int!
uid: String
title: String!
render: String
}
...
interface NodeInterface {
id: Int!
}
GQL;
}
/**
* {@inheritdoc}
*/
protected function getResolverRegistry() {
$builder = new ResolverBuilder();
$registry = new ResolverRegistry([
'Article' => ContextDefinition::create('entity:node')
->addConstraint('Bundle', 'article'),
'Page' => ContextDefinition::create('entity:node')
->addConstraint('Bundle', 'page'),
]);
...
return $registry;
}
}Enable the custom schema
Last updated