public static function UnionTypePluginBase::createInstance in GraphQL 8.3
Parameters
\Drupal\graphql\Plugin\SchemaBuilderInterface $builder:
\Drupal\graphql\Plugin\TypePluginManager $manager:
$definition:
$id:
Return value
mixed
Overrides TypePluginInterface::createInstance
File
- src/
Plugin/ GraphQL/ Unions/ UnionTypePluginBase.php, line 19
Class
Namespace
Drupal\graphql\Plugin\GraphQL\UnionsCode
public static function createInstance(SchemaBuilderInterface $builder, TypePluginManager $manager, $definition, $id) {
return new UnionType([
'name' => $definition['name'],
'description' => $definition['description'],
'types' => function () use ($builder, $definition) {
return array_map(function ($type) use ($builder) {
if (!($type = $builder
->getType($type)) instanceof ObjectType) {
throw new \LogicException('Union types can only reference object types.');
}
return $type;
}, $builder
->getSubTypes($definition['name']));
},
'resolveType' => function ($value, $context, $info) use ($builder, $definition) {
return $builder
->resolveType($definition['name'], $value, $context, $info);
},
]);
}