Created
April 27, 2019 09:46
-
-
Save blazeyo/ed0d2f77b90cfd90c14574786990287e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\my_module\Plugin\GraphQL\Fields\Entity; | |
use Drupal\Core\Entity\EntityInterface; | |
use Drupal\graphql\GraphQL\Execution\ResolveContext; | |
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; | |
use GraphQL\Type\Definition\ResolveInfo; | |
/** | |
* @GraphQLField( | |
* id = "node_story_field_paragraph_image", | |
* secure = true, | |
* name = "fieldImageFromParagraph", | |
* type = " FieldParagraphImageFieldImage", | |
* parents = {"NodeStory"} | |
* ) | |
*/ | |
class NodeStoryParagraphImage extends FieldPluginBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { | |
if ($value instanceof EntityInterface) { | |
$node = $value; | |
$paragraph = $this->getParagraphFromNode($node); | |
yield $parapraph->get('field_paragraph_image)->getValue(); | |
} | |
} | |
} | |
/* | |
Example usage: | |
{ | |
nodeById(id: "1") { | |
... on NodeStory { | |
fieldImageFromParagraph { | |
alt | |
title | |
url | |
} | |
} | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment