You are here

protected function FieldItemTypeResolver::getTypeIdentifier in GraphQL 8

Same name and namespace in other branches
  1. 8.2 src/TypeResolver/FieldItemTypeResolver.php \Drupal\graphql\TypeResolver\FieldItemTypeResolver::getTypeIdentifier()

Retrieves the unique type identifier for a specific data type.

For basic complex data types, this should be the data type identifier. However, for things like entities and field items, this must be more specific than the data type value returned by the definition object.

This is used to generate the schema type name of the complex data type object or interface for this type (e.g. entity:node:article becomes EntityNodeArticle).

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $type: The type definition for which to return the data type identifier.

Return value

string The data type identifier of the given type definition.

Overrides TypedDataTypeResolver::getTypeIdentifier

File

src/TypeResolver/FieldItemTypeResolver.php, line 56

Class

FieldItemTypeResolver
Resolves the schema for field definitions.

Namespace

Drupal\graphql\TypeResolver

Code

protected function getTypeIdentifier(DataDefinitionInterface $type) {

  /** @var FieldItemDataDefinition $type */
  $fieldDefinition = $type
    ->getFieldDefinition();
  $fieldName = $fieldDefinition
    ->getName();
  $entityTypeId = $fieldDefinition
    ->getTargetEntityTypeId();

  // Create a more specifc data type identifier because the one returned via
  // typed data is too vague and does not contain information about the owning
  // entity type.
  return "field:item:{$entityTypeId}:{$fieldName}";
}