Skip to content

Commit

Permalink
fix(graphql): AstManipulator::addTypeDefinition() will convert `Sca…
Browse files Browse the repository at this point in the history
…larType` into `scalar` and will add it into `Document` instead of `TypeRegistry`.

For other `Type`s the `NotImplemented` will be thrown (to indicate that the type will be lost if the Schema is cached).
  • Loading branch information
LastDragon-ru committed Aug 31, 2023
1 parent 0ee21c7 commit 3e23e8e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/graphql/src/Utils/AstManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,19 @@ public function addTypeDefinition(TypeDefinitionNode|Type $definition): TypeDefi

if ($definition instanceof TypeDefinitionNode && $definition instanceof Node) {
$this->getDocument()->setTypeDefinition($definition);
} elseif ($definition instanceof ScalarType) {
$class = json_encode($definition::class, JSON_THROW_ON_ERROR);
$scalar = Parser::scalarTypeDefinition(
<<<GRAPHQL
scalar {$name} @scalar(class: {$class})
GRAPHQL,
);

$this->getDocument()->setTypeDefinition($scalar);
} elseif ($definition instanceof Type) {
$this->getTypes()->register($definition);
// Types added while AST transformation will be lost if the Schema
// is cached. Not yet sure how to solve it... Any ideas?
throw new NotImplemented('`Type` registration');
} else {
// empty
}
Expand Down

0 comments on commit 3e23e8e

Please sign in to comment.