Skip to content

Commit 5da9890

Browse files
authored
fix(executor): Fix swapped errors and extensions property in execution results (drupal-graphql#1161)
1 parent 918fc4e commit 5da9890

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deprecated_swap_errors_and_extensions_in_results: false

config/schema/graphql.schema.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
graphql.settings:
2+
type: config_object
3+
label: "GraphQL Settings"
4+
mapping:
5+
deprecated_swap_errors_and_extensions_in_results:
6+
type: boolean
7+
label: "Return `errors` in the GraphQL response `extension` key and vice versa"
8+
description: "Preserves behaviour that was caused by a bug that caused errors to appear in the extensions key of GraphQL results. Ensures misbehaving client implementations don't break by fixing this bug. Will be removed in 5.0.0"
9+
110
graphql.graphql_servers.*:
211
type: config_entity
312
label: 'Server'

graphql.install

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ function graphql_update_8001(): void {
6363
$server->save();
6464
}
6565
}
66+
67+
/**
68+
* Preserve incorrect error reporting behaviour for PR #1161.
69+
*/
70+
function graphql_update_8400() :void {
71+
\Drupal::configFactory()->getEditable('graphql.settings')
72+
->set('deprecated_swap_errors_and_extensions_in_results', TRUE)
73+
->save();
74+
}

src/GraphQL/Execution/Executor.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@ public function doExecute(): Promise {
223223
return $this->doExecuteUncached()->then(function ($result) {
224224
$this->context->mergeCacheMaxAge(0);
225225

226-
$result = new CacheableExecutionResult($result->data, $result->extensions, $result->errors);
226+
// @todo keep only else case in 5.0.0.
227+
if (\Drupal::config('graphql.settings')->get('deprecated_swap_errors_and_extensions_in_results')) {
228+
$result = new CacheableExecutionResult($result->data, $result->extensions, $result->errors);
229+
}
230+
else {
231+
$result = new CacheableExecutionResult($result->data, $result->errors, $result->extensions);
232+
}
227233
$result->addCacheableDependency($this->context);
228234
return $result;
229235
});
@@ -246,7 +252,13 @@ protected function doExecuteCached($prefix) {
246252
$this->context->mergeCacheMaxAge(0);
247253
}
248254

249-
$result = new CacheableExecutionResult($result->data, $result->extensions, $result->errors);
255+
// @todo keep only else case in 5.0.0.
256+
if (\Drupal::config('graphql.settings')->get('deprecated_swap_errors_and_extensions_in_results')) {
257+
$result = new CacheableExecutionResult($result->data, $result->extensions, $result->errors);
258+
}
259+
else {
260+
$result = new CacheableExecutionResult($result->data, $result->errors, $result->extensions);
261+
}
250262
$result->addCacheableDependency($this->context);
251263
if ($result->getCacheMaxAge() !== 0) {
252264
$this->cacheWrite($prefix, $result);

0 commit comments

Comments
 (0)