Skip to content

Commit 08f1556

Browse files
ruudkspawnia
authored andcommitted
Improve Type::getNamedType return type
Only when null is passed, it will return null. Otherwise it will always be Type&NamedType.
1 parent 060013e commit 08f1556

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

docs/class-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ static function isInputType($type): bool
270270
*
271271
* @return (Type&NamedType)|null
272272
*
273+
* @phpstan-return ($type is null ? null : Type&NamedType)
274+
*
273275
* @api
274276
*/
275277
static function getNamedType(?GraphQL\Type\Definition\Type $type): ?GraphQL\Type\Definition\Type

src/Type/Definition/QueryPlan.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ private function analyzeQueryPlan(ObjectType $parentType, iterable $fieldNodes):
133133
$type = Type::getNamedType(
134134
$parentType->getField($fieldNode->name->value)->getType()
135135
);
136-
assert($type instanceof Type, 'known because schema validation');
137136

138137
$subfields = $this->analyzeSelectionSet($fieldNode->selectionSet, $type, $implementors);
139138
$queryPlan = $this->arrayMergeDeep($queryPlan, $subfields);

src/Type/Definition/Type.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public static function isInputType($type): bool
192192
*
193193
* @return (Type&NamedType)|null
194194
*
195+
* @phpstan-return ($type is null ? null : Type&NamedType)
196+
*
195197
* @api
196198
*/
197199
public static function getNamedType(?Type $type): ?Type

src/Type/SchemaValidationContext.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ private function validateTypeIsSingleton(Type $type, string $path): void
835835
}
836836

837837
$namedType = Type::getNamedType($type);
838-
assert($namedType !== null, 'because getNamedType() was called with non-null type');
839838
if ($namedType->isBuiltInType()) {
840839
return;
841840
}

0 commit comments

Comments
 (0)