Skip to content

Commit

Permalink
Merge pull request #24 from x-graphql/fix/skip-null-variable-when-del…
Browse files Browse the repository at this point in the history
…egating-query

fix: skip null variable when delegating query
  • Loading branch information
vuongxuongminh authored Apr 25, 2024
2 parents 52c0e99 + b2635c8 commit baa82e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Execution/DelegateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private function collectVariables(OperationDefinitionNode $operation, array $fra
];

foreach ($names as $name) {
if (isset($this->variables[$name])) {
if (array_key_exists($name, $this->variables)) {
$variables[$name] = $this->variables[$name];
}
}
Expand Down
23 changes: 21 additions & 2 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,25 @@ public static function executionProvider(): array
]
]
],
'use null variable' => [
<<<'GQL'
query($code: ID) {
findPersonByLanguageCode(code: $code) {
name
}
}
GQL,
[
'code' => null
],
[
'data' => [
'findPersonByLanguageCode' => [
'name' => 'John Doe unknown',
]
]
],
]
];
}

Expand Down Expand Up @@ -593,10 +612,10 @@ private function createLocalSchema(): Schema
'findPersonByLanguageCode' => [
'type' => $personType,
'args' => [
'code' => Type::nonNull(Type::id()),
'code' => Type::id(),
],
'resolve' => fn (mixed $rootValue, array $args) => [
'name' => 'John Doe ' . $args['code'],
'name' => 'John Doe ' . ($args['code'] ?? 'unknown'),
'languages' => (array)$args['code'],
],
]
Expand Down

0 comments on commit baa82e6

Please sign in to comment.