Extend type programatically #2617
Replies: 2 comments 1 reply
-
UPDATE: I have now, somewhat, managed to add the public function manipulateTypeDefinition(
DocumentAST &$documentAST,
TypeDefinitionNode &$typeDefinition
): void {
$typeName = $typeDefinition->getName()->value;
/** @var ObjectTypeDefinitionNode $rootType */
$rootType = $documentAST->types[$typeName];
$rootType->fields = ASTHelper::prepend(
$rootType->fields,
new FieldDefinitionNode([
'name' => new NameNode([
'value' => 'translations',
]),
'type' => new NonNullTypeNode([
'type' => new ListTypeNode([
'type' => new NonNullTypeNode([
'type' => new NamedTypeNode([
'name' => new NameNode([
'value' => $typeName . 'Translation',
]),
]),
]),
]),
]),
'directives' => new NodeList([]),
'arguments' => new NodeList([]),
]),
);
} |
Beta Was this translation helpful? Give feedback.
-
You can take some inspiration from the lighthouse/src/Pagination/PaginationManipulator.php Lines 96 to 105 in 0fe0f92 Especially using |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am creating a custom directive that can be applied on a type definition. The aim is for it to generate an additional type, based on the type the directive is applied to and then extend the original type with an attribute that refers to the generated type.
I have managed to generate the new type programatically using the type registry in the
manipulateTypeDefinition
method to register a newObjectType
. However, I am am struggling to find a way to register a type extension.Here is what I am trying to achieve in a nutshell. Given this schema:
I want the following to be generated:
Any nudge in the right direction would be hugely appreciated!
Beta Was this translation helpful? Give feedback.
All reactions