You are here

protected function ThunderParagraphsSchemaExtension::resolveFields in Thunder 6.2.x

Add paragraph field resolvers.

1 call to ThunderParagraphsSchemaExtension::resolveFields()
ThunderParagraphsSchemaExtension::registerResolvers in modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderParagraphsSchemaExtension.php

File

modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderParagraphsSchemaExtension.php, line 41

Class

ThunderParagraphsSchemaExtension
The paragraph schema extension.

Namespace

Drupal\thunder_gqls\Plugin\GraphQL\SchemaExtension

Code

protected function resolveFields() {

  // Text.
  $this
    ->resolveParagraphInterfaceFields('ParagraphText');
  $this
    ->addFieldResolverIfNotExists('ParagraphText', 'text', $this->builder
    ->fromPath('entity', 'field_text.processed'));

  // Image.
  $this
    ->resolveParagraphInterfaceFields('ParagraphImage');
  $this
    ->addFieldResolverIfNotExists('ParagraphImage', 'image', $this->builder
    ->fromPath('entity', 'field_image.entity'));

  // Twitter.
  $this
    ->resolveParagraphInterfaceFields('ParagraphTwitter');
  $this
    ->addFieldResolverIfNotExists('ParagraphTwitter', 'url', $this->builder
    ->compose($this->builder
    ->fromPath('entity', 'field_media.entity'), $this->builder
    ->fromPath('entity', 'field_url.value')));

  // Instagram.
  $this
    ->resolveParagraphInterfaceFields('ParagraphInstagram');
  $this
    ->addFieldResolverIfNotExists('ParagraphInstagram', 'url', $this->builder
    ->compose($this->builder
    ->fromPath('entity', 'field_media.entity'), $this->builder
    ->fromPath('entity', 'field_url.value')));

  // Pinterest.
  $this
    ->resolveParagraphInterfaceFields('ParagraphPinterest');
  $this
    ->addFieldResolverIfNotExists('ParagraphPinterest', 'url', $this->builder
    ->compose($this->builder
    ->fromPath('entity', 'field_media.entity'), $this->builder
    ->fromPath('entity', 'field_url.value')));

  // Gallery.
  $this
    ->resolveParagraphInterfaceFields('ParagraphGallery');
  $this
    ->addFieldResolverIfNotExists('ParagraphGallery', 'name', $this->builder
    ->compose($this->builder
    ->fromPath('entity', 'field_media.entity'), $this->builder
    ->produce('entity_label')
    ->map('entity', $this->builder
    ->fromParent())));
  $this
    ->addFieldResolverIfNotExists('ParagraphGallery', 'images', $this->builder
    ->compose($this->builder
    ->fromPath('entity', 'field_media.entity'), $this
    ->fromEntityReference('field_media_images')));

  // Link.
  $this
    ->resolveParagraphInterfaceFields('ParagraphLink');
  $this
    ->addFieldResolverIfNotExists('ParagraphLink', 'links', $this->builder
    ->fromPath('entity', 'field_link'));

  // Video.
  $this
    ->resolveParagraphInterfaceFields('ParagraphVideo');
  $this
    ->addFieldResolverIfNotExists('ParagraphVideo', 'video', $this->builder
    ->fromPath('entity', 'field_video.entity'));

  // Quote.
  $this
    ->resolveParagraphInterfaceFields('ParagraphQuote');
  $this
    ->addFieldResolverIfNotExists('ParagraphQuote', 'text', $this->builder
    ->fromPath('entity', 'field_text.processed'));
}