modules/stanford_decoupled/src/Plugin/GraphQLCompose/FieldType/RedirectSourceItem.php
<?php
declare(strict_types=1);
namespace Drupal\stanford_decoupled\Plugin\GraphQLCompose\FieldType;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerItemInterface;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerTrait;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeBase;
/**
* {@inheritDoc}
*
* @codeCoverageIgnore Unclear how to test for this.
*
* @GraphQLComposeFieldType(
* id = "redirect_source",
* type_sdl = "RedirectSourceType",
* )
*/
class RedirectSourceItem extends GraphQLComposeFieldTypeBase implements FieldProducerItemInterface {
use FieldProducerTrait;
/**
* {@inheritdoc}
*/
public function resolveFieldItem(FieldItemInterface $item, FieldContext $context) {
$query = http_build_query($item->get('query')->getValue());
$path = $item->get('path')->getValue();
return [
'url' => trim('/' . $path . '?' . $query, '?'),
];
}
}