graphql_compose-1.0.0-beta20/src/Plugin/GraphQLCompose/FieldType/EntityIdItem.php

src/Plugin/GraphQLCompose/FieldType/EntityIdItem.php
<?php

declare(strict_types=1);

namespace Drupal\graphql_compose\Plugin\GraphQLCompose\FieldType;

use Drupal\graphql\GraphQL\Resolver\Composite;
use Drupal\graphql\GraphQL\ResolverBuilder;
use Drupal\graphql_compose\Attribute\FieldType;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeBase;

/**
 * {@inheritdoc}
 */
#[FieldType(
  id: "entity_id",
  type_sdl: "ID",
)]
class EntityIdItem extends GraphQLComposeFieldTypeBase {

  /**
   * {@inheritdoc}
   */
  public function getProducers(ResolverBuilder $builder): Composite {
    return $builder->compose(
      $builder->produce('entity_id')
        ->map('entity', $builder->fromParent()),

      // An id can be null during previews.
      $builder->callback(fn ($id) => $id ?: 0)
    );
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc