Skip to content

Commit

Permalink
Fix warning on missing entityLinks keys in GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen authored Nov 28, 2023
1 parent 37cdc44 commit 981e6b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/thunder_gqls/src/Traits/ResolverHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function fromEntityReferenceRevisions(string $field, $entity = NULL) {
public function addSimpleCallbackFields(string $type, array $fields): void {
foreach ($fields as $field) {
$this->addFieldResolverIfNotExists($type, $field,
$this->builder->callback(fn($arr) => $arr[$field])
$this->builder->callback(fn($arr) => $arr[$field] ?? NULL)
);
}
}
Expand Down
22 changes: 22 additions & 0 deletions modules/thunder_gqls/tests/src/Functional/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ public function testExpiredImage(): void {
], $this->jsonDecode($response->getBody())['data']['page']);
}

/**
* Validates that non-existing entity links do not generate a warning.
*/
public function testNonExistingEntityLinks(): void {
$query = <<<GQL
query (\$path: String!) {
page(path: \$path) {
entityLinks {
versionHistory
}
}
}
GQL;

$variables = ['path' => 'news'];
$response = $this->query($query, Json::encode($variables));
$page = $this->jsonDecode($response->getBody());
$this->assertArrayNotHasKey('errors', $page);
$this->assertNull($page['data']['page']['entityLinks']['versionHistory']);

}

/**
* Validates the thunder schema.
*/
Expand Down

0 comments on commit 981e6b2

Please sign in to comment.