Fix: type safety for TypeInfo

This commit is contained in:
Vladimir Razuvaev 2017-07-04 13:25:01 +07:00
parent 4c96193027
commit 32376dd6ee
2 changed files with 13 additions and 16 deletions

View File

@ -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:

View File

@ -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)) {
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(