protected function ThunderPagesSchemaExtension::resolveFields in Thunder 6.2.x
Add article field resolvers.
1 call to ThunderPagesSchemaExtension::resolveFields()
- ThunderPagesSchemaExtension::registerResolvers in modules/
thunder_gqls/ src/ Plugin/ GraphQL/ SchemaExtension/ ThunderPagesSchemaExtension.php
File
- modules/
thunder_gqls/ src/ Plugin/ GraphQL/ SchemaExtension/ ThunderPagesSchemaExtension.php, line 45
Class
- ThunderPagesSchemaExtension
- Schema extension for page types.
Namespace
Drupal\thunder_gqls\Plugin\GraphQL\SchemaExtensionCode
protected function resolveFields() {
// Page.
$this
->addFieldResolverIfNotExists('Query', 'page', $this
->fromRoute($this->builder
->fromArgument('path')));
// Teaser.
$this
->addSimpleCallbackFields('Teaser', [
'image',
'text',
]);
// Article.
$this
->resolvePageInterfaceFields('Article', 'node');
$this
->resolvePageInterfaceQueryFields('article', 'node');
$this
->addFieldResolverIfNotExists('Article', 'seoTitle', $this->builder
->fromPath('entity', 'field_seo_title.value'));
$this
->addFieldResolverIfNotExists('Article', 'channel', $this->builder
->fromPath('entity', 'field_channel.entity'));
$this
->addFieldResolverIfNotExists('Article', 'tags', $this
->fromEntityReference('field_tags'));
$this
->addFieldResolverIfNotExists('Article', 'content', $this
->fromEntityReferenceRevisions('field_paragraphs'));
$this
->addFieldResolverIfNotExists('Article', 'teaser', $this->builder
->callback(function (ContentEntityInterface $entity) {
return [
'image' => $entity->field_teaser_media->entity,
'text' => $entity->field_teaser_text->value,
];
}));
// Basic page.
$this
->resolvePageInterfaceFields('BasicPage', 'node');
$this
->addFieldResolverIfNotExists('BasicPage', 'content', $this->builder
->fromPath('entity', 'body.processed'));
// Tags.
$this
->resolvePageInterfaceFields('Tags', 'taxonomy_term');
$this
->resolvePageInterfaceQueryFields('tags', 'taxonomy_term');
$this
->addFieldResolverIfNotExists('Tags', 'content', $this
->fromEntityReferenceRevisions('field_paragraphs'));
$this
->addFieldResolverIfNotExists('Tags', 'articles', $this->builder
->produce('entities_with_term')
->map('term', $this->builder
->fromParent())
->map('type', $this->builder
->fromValue('node'))
->map('bundles', $this->builder
->fromValue([
'article',
]))
->map('field', $this->builder
->fromValue('field_tags'))
->map('offset', $this->builder
->fromArgument('offset'))
->map('limit', $this->builder
->fromArgument('limit'))
->map('languages', $this->builder
->fromArgument('languages'))
->map('sortBy', $this->builder
->fromValue([
[
'field' => 'created',
'direction' => 'DESC',
],
])));
// Channel.
$this
->resolvePageInterfaceFields('Channel', 'taxonomy_term');
$this
->resolvePageInterfaceQueryFields('channel', 'taxonomy_term');
$this
->addFieldResolverIfNotExists('Channel', 'content', $this
->fromEntityReferenceRevisions('field_paragraphs'));
$this
->addFieldResolverIfNotExists('Channel', 'parent', $this->builder
->fromPath('entity', 'parent.entity'));
$this
->addFieldResolverIfNotExists('Channel', 'articles', $this->builder
->produce('entities_with_term')
->map('term', $this->builder
->fromParent())
->map('type', $this->builder
->fromValue('node'))
->map('bundles', $this->builder
->fromValue([
'article',
]))
->map('field', $this->builder
->fromValue('field_channel'))
->map('offset', $this->builder
->fromArgument('offset'))
->map('limit', $this->builder
->fromArgument('limit'))
->map('languages', $this->builder
->fromArgument('languages'))
->map('sortBy', $this->builder
->fromValue([
[
'field' => 'created',
'direction' => 'DESC',
],
]))
->map('depth', $this->builder
->fromValue(1)));
// User.
$this
->resolvePageInterfaceFields('User', 'user');
$this
->resolvePageInterfaceQueryFields('user', 'user');
$this
->addFieldResolverIfNotExists('User', 'mail', $this->builder
->fromPath('entity', 'mail.value'));
$this
->addFieldResolverIfNotExists('User', 'access', $this->builder
->fromPath('entity', 'access.value'));
$this
->addFieldResolverIfNotExists('User', 'published', $this->builder
->fromPath('entity', 'status.value'));
$this
->addFieldResolverIfNotExists('User', 'picture', $this->builder
->produce('thunder_image')
->map('entity', $this->builder
->fromPath('entity', 'user_picture.entity'))
->map('field', $this->builder
->fromPath('entity', 'user_picture')));
// Entity List.
$this
->addFieldResolverIfNotExists('EntityList', 'total', $this->builder
->callback(function (EntityListResponse $entityList) {
return $entityList
->total();
}));
$this
->addFieldResolverIfNotExists('EntityList', 'items', $this->builder
->callback(function (EntityListResponse $entityList) {
return $entityList
->items();
}));
}