class ThunderSchema in Thunder 6.2.x
Tha base schema for Thunder composable schema.
Plugin annotation
@Schema(
id = "thunder",
name = "Thunder composable schema"
)
Hierarchy
- class \Drupal\thunder_gqls\Plugin\GraphQL\Schema\ThunderSchema extends \Drupal\graphql\Plugin\GraphQL\Schema\ComposableSchema uses ResolverHelperTrait
Expanded class hierarchy of ThunderSchema
File
- modules/
thunder_gqls/ src/ Plugin/ GraphQL/ Schema/ ThunderSchema.php, line 23
Namespace
Drupal\thunder_gqls\Plugin\GraphQL\SchemaView source
class ThunderSchema extends ComposableSchema {
use ResolverHelperTrait;
const REQUIRED_EXTENSIONS = [
'thunder_pages',
'thunder_media',
'thunder_paragraphs',
];
/**
* The data producer plugin manager.
*
* @var \Drupal\graphql\Plugin\DataProducerPluginManager
*/
protected $dataProducerManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$schema = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$schema
->setDataProducerManager($container
->get('plugin.manager.graphql.data_producer'));
return $schema;
}
/**
* Set the plugin manager.
*
* @param \Drupal\graphql\Plugin\DataProducerPluginManager $pluginManager
* The data producer plugin manager.
*/
protected function setDataProducerManager(DataProducerPluginManager $pluginManager) {
$this->dataProducerManager = $pluginManager;
}
/**
* {@inheritdoc}
*/
public function getResolverRegistry() {
$this->registry = new ResolverRegistry();
$this
->createResolverBuilder();
$this
->resolveBaseTypes();
$this
->addFieldResolverIfNotExists('Query', 'redirect', $this->builder
->produce('thunder_redirect')
->map('path', $this->builder
->fromArgument('path')));
if ($this->dataProducerManager
->hasDefinition('access_unpublished_token_set')) {
$this
->addFieldResolverIfNotExists('Query', 'accessUnpublishedToken', $this->builder
->produce('access_unpublished_token_set')
->map('token', $this->builder
->fromArgument('auHash')));
}
return $this->registry;
}
/**
* {@inheritdoc}
*/
protected function getExtensions() {
return array_map(function ($id) {
return $this->extensionManager
->createInstance($id);
}, array_unique(array_filter($this
->getConfiguration()['extensions']) + static::REQUIRED_EXTENSIONS));
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
foreach (Element::children($form['extensions']) as $extension) {
if (in_array($extension, static::REQUIRED_EXTENSIONS)) {
$form['extensions'][$extension]['#access'] = FALSE;
unset($form['extensions']['#options'][$extension]);
}
}
return $form;
}
/**
* {@inheritdoc}
*/
protected function getSchemaDefinition() {
return SdlSchemaPluginBase::getSchemaDefinition();
}
/**
* Resolve custom types, that are used in multiple places.
*/
private function resolveBaseTypes() {
$this
->addFieldResolverIfNotExists('Link', 'url', $this->builder
->callback(function ($parent) {
if (!empty($parent) && isset($parent['uri'])) {
$urlObject = Url::fromUri($parent['uri']);
$url = $urlObject
->toString(TRUE)
->getGeneratedUrl();
}
return $url ?? '';
}));
$this
->addSimpleCallbackFields('Link', [
'title',
]);
$this
->addSimpleCallbackFields('FocalPoint', [
'x',
'y',
]);
$this
->addSimpleCallbackFields('Redirect', [
'url',
'status',
]);
$this
->addSimpleCallbackFields('EntityLinks', [
'canonical',
'deleteForm',
'deleteMultipleForm',
'editForm',
'versionHistory',
'revision',
'create',
'latestVersion',
]);
$this
->addSimpleCallbackFields('Thumbnail', [
'src',
'width',
'height',
'alt',
'title',
]);
$this
->addSimpleCallbackFields('ImageDerivative', [
'src',
'width',
'height',
]);
$this
->addSimpleCallbackFields('Schema', [
'query',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResolverHelperTrait:: |
protected | property | ResolverBuilder. | |
ResolverHelperTrait:: |
protected | property | ResolverRegistryInterface. | |
ResolverHelperTrait:: |
protected | function | Add field resolver to registry, if it does not already exist. | |
ResolverHelperTrait:: |
public | function | Define callback field resolver for a type. | |
ResolverHelperTrait:: |
protected | function | Create the ResolverBuilder. | |
ResolverHelperTrait:: |
public | function | Produces an entity_reference field. | |
ResolverHelperTrait:: |
public | function | Produces an entity_reference_revisions field. | |
ResolverHelperTrait:: |
public | function | Produces an entity from a given path. | |
ThunderSchema:: |
protected | property | The data producer plugin manager. | |
ThunderSchema:: |
public | function | ||
ThunderSchema:: |
public static | function | ||
ThunderSchema:: |
protected | function | ||
ThunderSchema:: |
public | function | ||
ThunderSchema:: |
protected | function | ||
ThunderSchema:: |
constant | |||
ThunderSchema:: |
private | function | Resolve custom types, that are used in multiple places. | |
ThunderSchema:: |
protected | function | Set the plugin manager. |