Skip to content

Commit

Permalink
fix(graphql): AstManipulator::getScalarTypeDefinitionNode() will re…
Browse files Browse the repository at this point in the history
…turn the existing node if it is exist.
  • Loading branch information
LastDragon-ru committed Dec 24, 2022
1 parent 581be04 commit 5afdf10
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/graphql/src/Utils/AstManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,21 @@ public function removeTypeDefinition(string $name): void {
}

public function getScalarTypeDefinitionNode(string $scalar): ScalarTypeDefinitionNode {
// fixme(graphql): Is there any better way for this?
return Parser::scalarTypeDefinition("scalar {$scalar}");
// It can be defined inside schema
$node = $this->isTypeDefinitionExists($scalar)
? $this->getTypeDefinitionNode($scalar)
: null;

if (!$node) {
// or programmatically (and there is no definition...)
$node = Parser::scalarTypeDefinition("scalar {$scalar}");
} elseif (!($node instanceof ScalarTypeDefinitionNode)) {
throw new TypeDefinitionUnknown($scalar);
} else {
// empty
}

return $node;
}

/**
Expand Down

0 comments on commit 5afdf10

Please sign in to comment.