You are here

class ResolverBuilder in GraphQL 8.4

Wires and maps different resolvers together to build the GraphQL tree.

Hierarchy

Expanded class hierarchy of ResolverBuilder

5 files declare their use of ResolverBuilder
ComposableSchemaExampleExtension.php in examples/graphql_composable/src/Plugin/GraphQL/SchemaExtension/ComposableSchemaExampleExtension.php
EntityDefinitionTest.php in tests/src/Kernel/DataProducer/EntityDefinitionTest.php
ExampleSchema.php in examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php
ExampleSchemaExtension.php in examples/graphql_example/src/Plugin/GraphQL/SchemaExtension/ExampleSchemaExtension.php
GraphQLTestBase.php in tests/src/Kernel/GraphQLTestBase.php

File

src/GraphQL/ResolverBuilder.php, line 24

Namespace

Drupal\graphql\GraphQL
View source
class ResolverBuilder {
  use TypedDataTrait;
  use DataFetcherTrait;

  /**
   * Instantiate a data producer proxy to lazy resolve a data producer plugin.
   *
   * @param string $id
   * @param array $config
   *
   * @return \Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerProxy
   */
  public function produce($id, array $config = []) {
    return DataProducerProxy::create($id, $config);
  }

  /**
   * Combine multiple resolvers in a chain resolving after each other.
   *
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface ...$resolvers
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Composite
   */
  public function compose(ResolverInterface ...$resolvers) {
    return new Composite($resolvers);
  }

  /**
   * Register a resolver.
   *
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $callback
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Tap
   */
  public function tap(ResolverInterface $callback) {
    return new Tap($callback);
  }

  /**
   * Register a resolver for multiple items.
   *
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $callback
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Map
   */
  public function map(ResolverInterface $callback) {
    return new Map($callback);
  }

  /**
   * Register a callback as resolver.
   *
   * @param callable $callback
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Callback
   */
  public function callback(callable $callback) {
    return new Callback($callback);
  }

  /**
   * Add a context that is available for further resolvers.
   *
   * @param string $name
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $source
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Tap
   */
  public function context($name, ResolverInterface $source = NULL) {
    $callback = new SourceContext($name, $source);
    return $this
      ->tap($callback);
  }

  /**
   * Add condition branches to resolve.
   *
   * @param array $branches
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Condition
   */
  public function cond(array $branches) {
    return new Condition($branches);
  }

  /**
   * Add a property path resolver.
   *
   * @param string $type
   * @param string $path
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $value
   *
   * @return \Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerProxy
   */
  public function fromPath($type, $path, ResolverInterface $value = NULL) {
    return $this
      ->produce('property_path')
      ->map('type', $this
      ->fromValue($type))
      ->map('path', $this
      ->fromValue($path))
      ->map('value', $value ?: $this
      ->fromParent());
  }

  /**
   * Adds a fixed value to resolve to.
   *
   * @param mixed $value
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Value
   */
  public function fromValue($value) {
    return new Value($value);
  }

  /**
   * Adds a query argument value to resolve to.
   *
   * @param string $name
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Argument
   */
  public function fromArgument($name) {
    return new Argument($name);
  }

  /**
   * Resolves the current value that will be a parent for the field.
   *
   * @return \Drupal\graphql\GraphQL\Resolver\ParentValue
   */
  public function fromParent() {
    return new ParentValue();
  }

  /**
   * Resolves a value from the context by context name.
   *
   * @param string $name
   * @param callable|null $default
   *
   * @return \Drupal\graphql\GraphQL\Resolver\Context
   */
  public function fromContext($name, $default = NULL) {
    return new Context($name, $default);
  }

  /**
   * Adds a default value resolver.
   *
   * @param mixed $value
   * @param mixed $default
   *
   * @return \Drupal\graphql\GraphQL\Resolver\DefaultValue
   */
  public function defaultValue($value, $default) {
    return new DefaultValue($value, $default);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DataFetcherTrait::$dataFetcher protected property The data fetcher.
DataFetcherTrait::getDataFetcher public function Gets the data fetcher.
DataFetcherTrait::setDataFetcher public function Sets the data fetcher.
ResolverBuilder::callback public function Register a callback as resolver.
ResolverBuilder::compose public function Combine multiple resolvers in a chain resolving after each other.
ResolverBuilder::cond public function Add condition branches to resolve.
ResolverBuilder::context public function Add a context that is available for further resolvers.
ResolverBuilder::defaultValue public function Adds a default value resolver.
ResolverBuilder::fromArgument public function Adds a query argument value to resolve to.
ResolverBuilder::fromContext public function Resolves a value from the context by context name.
ResolverBuilder::fromParent public function Resolves the current value that will be a parent for the field.
ResolverBuilder::fromPath public function Add a property path resolver.
ResolverBuilder::fromValue public function Adds a fixed value to resolve to.
ResolverBuilder::map public function Register a resolver for multiple items.
ResolverBuilder::produce public function Instantiate a data producer proxy to lazy resolve a data producer plugin.
ResolverBuilder::tap public function Register a resolver.
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2