mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 22:36:02 +03:00
Fix: type safety for TypeInfo
This commit is contained in:
parent
4c96193027
commit
32376dd6ee
@ -388,12 +388,7 @@ class TypeInfo
|
||||
switch ($node->kind) {
|
||||
case NodeKind::SELECTION_SET:
|
||||
$namedType = Type::getNamedType($this->getType());
|
||||
$compositeType = null;
|
||||
if (Type::isCompositeType($namedType)) {
|
||||
// isCompositeType is a type refining predicate, so this is safe.
|
||||
$compositeType = $namedType;
|
||||
}
|
||||
$this->parentTypeStack[] = $compositeType; // push
|
||||
$this->parentTypeStack[] = Type::isCompositeType($namedType) ? $namedType : null;
|
||||
break;
|
||||
|
||||
case NodeKind::FIELD:
|
||||
@ -426,12 +421,12 @@ class TypeInfo
|
||||
case NodeKind::FRAGMENT_DEFINITION:
|
||||
$typeConditionNode = $node->typeCondition;
|
||||
$outputType = $typeConditionNode ? self::typeFromAST($schema, $typeConditionNode) : $this->getType();
|
||||
$this->typeStack[] = $outputType; // push
|
||||
$this->typeStack[] = Type::isOutputType($outputType) ? $outputType : null; // push
|
||||
break;
|
||||
|
||||
case NodeKind::VARIABLE_DEFINITION:
|
||||
$inputType = self::typeFromAST($schema, $node->type);
|
||||
$this->inputTypeStack[] = $inputType; // push
|
||||
$this->inputTypeStack[] = Type::isInputType($inputType) ? $inputType : null; // push
|
||||
break;
|
||||
|
||||
case NodeKind::ARGUMENT:
|
||||
|
@ -7,6 +7,7 @@ use GraphQL\Language\AST\InlineFragmentNode;
|
||||
use GraphQL\Language\AST\NodeKind;
|
||||
use GraphQL\Language\Printer;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\TypeInfo;
|
||||
use GraphQL\Validator\ValidationContext;
|
||||
|
||||
class FragmentsOnCompositeTypes
|
||||
@ -25,17 +26,18 @@ class FragmentsOnCompositeTypes
|
||||
{
|
||||
return [
|
||||
NodeKind::INLINE_FRAGMENT => function(InlineFragmentNode $node) use ($context) {
|
||||
$type = $context->getType();
|
||||
|
||||
if ($node->typeCondition && $type && !Type::isCompositeType($type)) {
|
||||
$context->reportError(new Error(
|
||||
static::inlineFragmentOnNonCompositeErrorMessage($type),
|
||||
[$node->typeCondition]
|
||||
));
|
||||
if ($node->typeCondition) {
|
||||
$type = TypeInfo::typeFromAST($context->getSchema(), $node->typeCondition);
|
||||
if ($type && !Type::isCompositeType($type)) {
|
||||
$context->reportError(new Error(
|
||||
static::inlineFragmentOnNonCompositeErrorMessage($type),
|
||||
[$node->typeCondition]
|
||||
));
|
||||
}
|
||||
}
|
||||
},
|
||||
NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) use ($context) {
|
||||
$type = $context->getType();
|
||||
$type = TypeInfo::typeFromAST($context->getSchema(), $node->typeCondition);
|
||||
|
||||
if ($type && !Type::isCompositeType($type)) {
|
||||
$context->reportError(new Error(
|
||||
|
Loading…
Reference in New Issue
Block a user