class ExampleSchema in GraphQL 8.4
Plugin annotation
@Schema(
id = "example",
name = "Example schema"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase implements CacheableDependencyInterface, ContainerFactoryPluginInterface, SchemaPluginInterface uses RefinableCacheableDependencyTrait
- class \Drupal\graphql_examples\Plugin\GraphQL\Schema\ExampleSchema
- class \Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase implements CacheableDependencyInterface, ContainerFactoryPluginInterface, SchemaPluginInterface uses RefinableCacheableDependencyTrait
Expanded class hierarchy of ExampleSchema
File
- examples/
graphql_example/ src/ Plugin/ GraphQL/ Schema/ ExampleSchema.php, line 16
Namespace
Drupal\graphql_examples\Plugin\GraphQL\SchemaView source
class ExampleSchema extends SdlSchemaPluginBase {
/**
* {@inheritdoc}
*/
public function getResolverRegistry() {
$builder = new ResolverBuilder();
$registry = new ResolverRegistry();
$this
->addQueryFields($registry, $builder);
$this
->addArticleFields($registry, $builder);
// Re-usable connection type fields.
$this
->addConnectionFields('ArticleConnection', $registry, $builder);
return $registry;
}
/**
* @param \Drupal\graphql\GraphQL\ResolverRegistry $registry
* @param \Drupal\graphql\GraphQL\ResolverBuilder $builder
*/
protected function addArticleFields(ResolverRegistry $registry, ResolverBuilder $builder) : void {
$registry
->addFieldResolver('Article', 'id', $builder
->produce('entity_id')
->map('entity', $builder
->fromParent()));
$registry
->addFieldResolver('Article', 'title', $builder
->compose($builder
->produce('entity_label')
->map('entity', $builder
->fromParent()), $builder
->produce('uppercase')
->map('string', $builder
->fromParent())));
$registry
->addFieldResolver('Article', 'author', $builder
->compose($builder
->produce('entity_owner')
->map('entity', $builder
->fromParent()), $builder
->produce('entity_label')
->map('entity', $builder
->fromParent())));
}
/**
* @param \Drupal\graphql\GraphQL\ResolverRegistry $registry
* @param \Drupal\graphql\GraphQL\ResolverBuilder $builder
*/
protected function addQueryFields(ResolverRegistry $registry, ResolverBuilder $builder) : void {
$registry
->addFieldResolver('Query', 'article', $builder
->produce('entity_load')
->map('type', $builder
->fromValue('node'))
->map('bundles', $builder
->fromValue([
'article',
]))
->map('id', $builder
->fromArgument('id')));
$registry
->addFieldResolver('Query', 'articles', $builder
->produce('query_articles')
->map('offset', $builder
->fromArgument('offset'))
->map('limit', $builder
->fromArgument('limit')));
}
/**
* @param string $type
* @param \Drupal\graphql\GraphQL\ResolverRegistry $registry
* @param \Drupal\graphql\GraphQL\ResolverBuilder $builder
*/
protected function addConnectionFields($type, ResolverRegistry $registry, ResolverBuilder $builder) : void {
$registry
->addFieldResolver($type, 'total', $builder
->callback(function (QueryConnection $connection) {
return $connection
->total();
}));
$registry
->addFieldResolver($type, 'items', $builder
->callback(function (QueryConnection $connection) {
return $connection
->items();
}));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
ExampleSchema:: |
protected | function | ||
ExampleSchema:: |
protected | function | ||
ExampleSchema:: |
protected | function | ||
ExampleSchema:: |
public | function |
Retrieves the resolver registry. Overrides SchemaPluginInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
SdlSchemaPluginBase:: |
protected | property | The cache bin for caching the parsed SDL. | |
SdlSchemaPluginBase:: |
protected | property | The schema extension plugin manager. | |
SdlSchemaPluginBase:: |
protected | property | Whether the system is currently in development mode. | |
SdlSchemaPluginBase:: |
protected | property | The module handler service. | |
SdlSchemaPluginBase:: |
public static | function |
@codeCoverageIgnore Overrides ContainerFactoryPluginInterface:: |
|
SdlSchemaPluginBase:: |
protected | function | Retrieves the parsed AST of the schema extension definitions. | |
SdlSchemaPluginBase:: |
protected | function | 1 | |
SdlSchemaPluginBase:: |
public | function |
Overrides SchemaPluginInterface:: |
|
SdlSchemaPluginBase:: |
protected | function | Retrieves the raw schema definition string. | 1 |
SdlSchemaPluginBase:: |
protected | function | Retrieves the parsed AST of the schema definition. | |
SdlSchemaPluginBase:: |
public | function |
SdlSchemaPluginBase constructor. Overrides PluginBase:: |