You are here

protected function ExampleSchema::addArticleFields in GraphQL 8.4

Parameters

\Drupal\graphql\GraphQL\ResolverRegistry $registry:

\Drupal\graphql\GraphQL\ResolverBuilder $builder:

1 call to ExampleSchema::addArticleFields()
ExampleSchema::getResolverRegistry in examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php
Retrieves the resolver registry.

File

examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php, line 38

Class

ExampleSchema
Plugin annotation @Schema( id = "example", name = "Example schema" )

Namespace

Drupal\graphql_examples\Plugin\GraphQL\Schema

Code

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())));
}