graphql_compose-1.0.0-beta20/modules/graphql_compose_edges/src/Plugin/GraphQL/DataProducer/ConnectionEdges.php
modules/graphql_compose_edges/src/Plugin/GraphQL/DataProducer/ConnectionEdges.php
<?php
declare(strict_types=1);
namespace Drupal\graphql_compose_edges\Plugin\GraphQL\DataProducer;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\graphql\Attribute\DataProducer;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\DataProducerPluginCachingInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\graphql_compose_edges\ConnectionInterface;
/**
* Produces the edges from a connection object.
*/
#[DataProducer(
id: "connection_edges",
name: new TranslatableMarkup("Connection edges"),
description: new TranslatableMarkup("Returns the edges of a connection."),
produces: new ContextDefinition(
data_type: "any",
label: new TranslatableMarkup("Edges"),
),
consumes: [
"connection" => new ContextDefinition(
data_type: "any",
label: new TranslatableMarkup("Query Connection"),
),
],
)]
class ConnectionEdges extends DataProducerPluginBase implements DataProducerPluginCachingInterface {
/**
* Resolves the request.
*
* @param \Drupal\graphql_compose_edges\ConnectionInterface $connection
* The connection to return the edges from.
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
* The cache context for this query.
*
* @return mixed
* The edges for the connection.
*/
public function resolve(ConnectionInterface $connection, FieldContext $context) {
return $connection->setCacheContext($context)->edges();
}
}
