1 | <?php |
||||
2 | |||||
3 | namespace Digia\GraphQL\Validation\Rule; |
||||
4 | |||||
5 | use Digia\GraphQL\Language\Node\FragmentSpreadNode; |
||||
6 | use Digia\GraphQL\Language\Visitor\VisitorResult; |
||||
7 | use Digia\GraphQL\Validation\ValidationException; |
||||
8 | use function Digia\GraphQL\Validation\unknownFragmentMessage; |
||||
9 | |||||
10 | /** |
||||
11 | * Known fragment names |
||||
12 | * |
||||
13 | * A GraphQL document is only valid if all `...Fragment` fragment spreads refer |
||||
14 | * to fragments defined in the same document. |
||||
15 | */ |
||||
16 | class KnownFragmentNamesRule extends AbstractRule |
||||
17 | { |
||||
18 | /** |
||||
19 | * @inheritdoc |
||||
20 | */ |
||||
21 | public function enterFragmentSpread(FragmentSpreadNode $node): VisitorResult |
||||
22 | { |
||||
23 | $fragmentName = $node->getNameValue(); |
||||
24 | $fragment = $this->context->getFragment($fragmentName); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
25 | |||||
26 | if (null === $fragment) { |
||||
27 | $this->context->reportError( |
||||
28 | new ValidationException(unknownFragmentMessage($fragmentName), [$node->getName()]) |
||||
0 ignored issues
–
show
It seems like
$fragmentName can also be of type null ; however, parameter $fragmentName of Digia\GraphQL\Validation\unknownFragmentMessage() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
29 | ); |
||||
30 | } |
||||
31 | |||||
32 | return new VisitorResult($node); |
||||
33 | } |
||||
34 | } |
||||
35 |