Automattic\WooCommerce\Vendor\GraphQL\Utils
ASTDefinitionBuilder::makeUnionDef
Method of the class: ASTDefinitionBuilder{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->makeUnionDef( $def ): UnionType;
- $def(UnionTypeDefinitionNode) (required)
- .
ASTDefinitionBuilder::makeUnionDef() ASTDefinitionBuilder::makeUnionDef code WC 10.9.1
private function makeUnionDef(UnionTypeDefinitionNode $def): UnionType
{
$name = $def->name->value;
/** @var array<UnionTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
return new UnionType([
'name' => $name,
'description' => $def->description->value ?? null,
// Note: While this could make assertions to get the correctly typed
// values below, that would throw immediately while type system
// validation with validateSchema() will produce more actionable results.
'types' => function () use ($def, $extensionASTNodes): array {
$types = [];
foreach ([$def, ...$extensionASTNodes] as $node) {
foreach ($node->types as $type) {
$types[] = $this->buildType($type);
}
}
/** @var array<int, ObjectType> $types */
return $types;
},
'astNode' => $def,
'extensionASTNodes' => $extensionASTNodes,
]);
}