You are here

class ResolverRegistry in Open Social 10.0.x

Same name and namespace in other branches
  1. 10.3.x modules/custom/social_graphql/src/GraphQL/ResolverRegistry.php \Drupal\social_graphql\GraphQL\ResolverRegistry
  2. 10.1.x modules/custom/social_graphql/src/GraphQL/ResolverRegistry.php \Drupal\social_graphql\GraphQL\ResolverRegistry
  3. 10.2.x modules/custom/social_graphql/src/GraphQL/ResolverRegistry.php \Drupal\social_graphql\GraphQL\ResolverRegistry

The Open Social resolver registry.

Extends the base ResolverRegistry from GraphQL to try to resolve fields on implemented interfaces when a field resolver for the type isn't found.

Hierarchy

  • class \Drupal\social_graphql\GraphQL\ResolverRegistry extends \Drupal\graphql\GraphQL\ResolverRegistry

Expanded class hierarchy of ResolverRegistry

1 file declares its use of ResolverRegistry
OpenSocialBaseSchema.php in modules/custom/social_graphql/src/Plugin/GraphQL/Schema/OpenSocialBaseSchema.php

File

modules/custom/social_graphql/src/GraphQL/ResolverRegistry.php, line 15

Namespace

Drupal\social_graphql\GraphQL
View source
class ResolverRegistry extends ResolverRegistryBase {

  /**
   * Return all field resolvers in the registry.
   *
   * @return callable[]
   *   A nested list of callables, keyed by type and field name.
   */
  public function getAllFieldResolvers() : array {
    return $this->fieldResolvers;
  }

  /**
   * {@inheritdoc}
   */
  protected function getRuntimeFieldResolver($value, $args, ResolveContext $context, ResolveInfo $info) {

    // Try the default implementation but fallback to trying the interfaces.
    return parent::getRuntimeFieldResolver($value, $args, $context, $info) ?? $this
      ->getRuntimeFieldResolverOnInterface($value, $args, $context, $info);
  }

  /**
   * Attempts to find a resolver on an implemented interface.
   *
   * @param mixed $value
   *   Value passed by getRuntimeFieldResolver.
   * @param string $args
   *   Args passed by getRuntimeFieldResolver.
   * @param \Drupal\graphql\GraphQL\Execution\ResolveContext $context
   *   Context passed by getRuntimeFieldResolver.
   * @param \GraphQL\Type\Definition\ResolveInfo $info
   *   Info passed by getRuntimeFieldResolver.
   *
   * @return callable|null
   *   The resolver for the field or null if none was found.
   */
  protected function getRuntimeFieldResolverOnInterface($value, $args, ResolveContext $context, ResolveInfo $info) {

    // Go through the interfaces implemented for the type on which this field is
    // resolved and check if they lead to a field resolution.
    $interfaces = $info->parentType
      ->getInterfaces();
    foreach ($interfaces as $interface) {
      if ($resolver = $this
        ->getFieldResolver($interface->name, $info->fieldName)) {
        return $resolver;
      }
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResolverRegistry::getAllFieldResolvers public function Return all field resolvers in the registry.
ResolverRegistry::getRuntimeFieldResolver protected function
ResolverRegistry::getRuntimeFieldResolverOnInterface protected function Attempts to find a resolver on an implemented interface.