You are here

public function ResolverRegistry::getFieldResolverWithInheritance in GraphQL 8.4

Get a field resolver for the type or any of the interfaces it implements.

This allows common functionality (such as for Edge's or Connections) to be implemented for an interface and re-used on any concrete type that extends it.

This should be used instead of `getFieldResolver` unless you're certain you want the resolver only for the specific type.

@todo This should be added to ResolverRegistryInterface in 5.0.0.

Parameters

\GraphQL\Type\Definition\Type $type: The type to find a resolver for.

string $fieldName: The name of the field to find a resolver for.

Return value

\Drupal\graphql\GraphQL\Resolver\ResolverInterface|null The defined resolver for the field or NULL if none exists.

1 call to ResolverRegistry::getFieldResolverWithInheritance()
ResolverRegistry::getRuntimeFieldResolver in src/GraphQL/ResolverRegistry.php
Returns the field resolver that should be used at runtime.

File

src/GraphQL/ResolverRegistry.php, line 167

Class

ResolverRegistry
Contains all the mappings how to resolve a GraphQL request.

Namespace

Drupal\graphql\GraphQL

Code

public function getFieldResolverWithInheritance(Type $type, string $fieldName) : ?ResolverInterface {
  if ($resolver = $this
    ->getFieldResolver($type->name, $fieldName)) {
    return $resolver;
  }
  if (!$type instanceof ImplementingType) {
    return NULL;
  }

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