Skip to content

Commit 466dece

Browse files
authored
chore(webonyx/graphql): Update GraphQL PHP dependency to v14.3.0 (drupal-graphql#1086)
1 parent e648d86 commit 466dece

File tree

11 files changed

+73
-32
lines changed

11 files changed

+73
-32
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ install:
9595
# Require redirect module to prevent PHPStan error on an optional dependency.
9696
# Install PHPStan to check for Drupal standards.
9797
- composer --no-interaction --working-dir=$DRUPAL_BUILD_DIR require \
98-
webonyx/graphql-php:^0.13.1 \
98+
webonyx/graphql-php:^14.3 \
9999
drupal/typed_data:^1.0 \
100100
drupal/redirect:^1.6 \
101101
phpstan/phpstan:^0.12.50 \

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "GPL-2.0+",
77
"require": {
88
"php": ">=7.2",
9-
"webonyx/graphql-php": "^0.13.1"
9+
"webonyx/graphql-php": "^14.3.0"
1010
},
1111
"minimum-stability": "dev"
1212
}

config/schema/graphql.schema.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ graphql.graphql_servers.*:
1111
endpoint:
1212
type: string
1313
label: 'Endpoint'
14-
debug:
15-
type: boolean
16-
label: 'Debug'
14+
debug_flag:
15+
type: integer
16+
label: 'Debug Flag'
1717
schema:
1818
type: string
1919
label: 'Schema'

graphql.install

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Install, update and uninstall functions for the GraphQL module.
66
*/
77

8+
use Drupal\graphql\Entity\Server;
9+
use GraphQL\Error\DebugFlag;
10+
811
/**
912
* Implements hook_requirements().
1013
*/
@@ -39,3 +42,24 @@ function graphql_uninstall() {
3942
}
4043
$languageTypes->set('negotiation', $negotiation)->save();
4144
}
45+
46+
/**
47+
* Update GraphQL Server debug configuration value.
48+
*/
49+
function graphql_update_8001() {
50+
// The `debug` config item has changed to `debug_flag`. It is no longer a
51+
// boolean toggle but instead a set of flags providing more control. In this
52+
// case we default to debug messages and a backtrace in case debugging was
53+
// enabled and just unselect all flags otherwise.
54+
$servers = Server::loadMultiple();
55+
foreach ($servers as $server) {
56+
// There is no need to unset `debug` as its property no longer exists so it
57+
// will not get persisted.
58+
$debugEnabled = (bool) $server->get('debug');
59+
$server->set(
60+
'debug_flag',
61+
$debugEnabled ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : DebugFlag::NONE
62+
);
63+
$server->save();
64+
}
65+
}

src/Entity/Server.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Drupal\graphql\GraphQL\Execution\ExecutionResult as CacheableExecutionResult;
1111
use Drupal\graphql\GraphQL\Execution\FieldContext;
1212
use Drupal\graphql\Plugin\PersistedQueryPluginInterface;
13+
use GraphQL\Error\DebugFlag;
1314
use GraphQL\Server\OperationParams;
1415
use Drupal\graphql\GraphQL\Execution\ResolveContext;
1516
use GraphQL\Server\ServerConfig;
@@ -51,7 +52,7 @@
5152
* "schema_configuration",
5253
* "persisted_queries_settings",
5354
* "endpoint",
54-
* "debug",
55+
* "debug_flag",
5556
* "caching",
5657
* "batching"
5758
* },
@@ -96,11 +97,12 @@ class Server extends ConfigEntityBase implements ServerInterface {
9697
public $schema_configuration = [];
9798

9899
/**
99-
* Whether the server is in debug mode.
100+
* The debug settings for this server.
100101
*
101-
* @var bool
102+
* @var int
103+
* @see \GraphQL\Error\DebugFlag
102104
*/
103-
public $debug = FALSE;
105+
public $debug_flag = DebugFlag::NONE;
104106

105107
/**
106108
* Whether the server should cache its results.
@@ -211,7 +213,7 @@ public function configuration() {
211213
// Create the server config.
212214
$registry = $plugin->getResolverRegistry();
213215
$server = ServerConfig::create();
214-
$server->setDebug(!!$this->get('debug'));
216+
$server->setDebugFlag($this->get('debug_flag'));
215217
$server->setQueryBatching(!!$this->get('batching'));
216218
$server->setValidationRules($this->getValidationRules());
217219
$server->setPersistentQueryLoader($this->getPersistedQueryLoader());

src/Form/ServerForm.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Drupal\Core\Plugin\PluginFormInterface;
1414
use Drupal\Core\Routing\RequestContext;
1515
use Drupal\graphql\Plugin\SchemaPluginManager;
16+
use GraphQL\Error\DebugFlag;
1617
use Symfony\Component\DependencyInjection\ContainerInterface;
1718

1819
/**
@@ -181,11 +182,23 @@ public function form(array $form, FormStateInterface $formState) {
181182
'#description' => $this->t('Whether caching of queries and partial results is enabled.'),
182183
];
183184

184-
$form['debug'] = [
185-
'#title' => $this->t('Enable debugging'),
186-
'#type' => 'checkbox',
187-
'#default_value' => !!$server->get('debug'),
188-
'#description' => $this->t('In debugging mode, error messages contain more verbose information in the query response.'),
185+
$debug_flags = $server->get('debug_flag') ?? 0;
186+
$form['debug_flag'] = [
187+
'#title' => $this->t('Debug settings'),
188+
'#type' => 'checkboxes',
189+
'#options' => [
190+
DebugFlag::INCLUDE_DEBUG_MESSAGE => $this->t("Add debugMessage key containing the exception message to errors."),
191+
DebugFlag::INCLUDE_TRACE => $this->t("Include the formatted original backtrace in errors."),
192+
DebugFlag::RETHROW_INTERNAL_EXCEPTIONS => $this->t("Rethrow the internal GraphQL exceptions"),
193+
DebugFlag::RETHROW_UNSAFE_EXCEPTIONS => $this->t("Rethrow unsafe GraphQL exceptions, these are exceptions that have not been marked as safe to expose to clients."),
194+
],
195+
'#default_value' => array_keys(array_filter([
196+
DebugFlag::INCLUDE_DEBUG_MESSAGE => (bool) ($debug_flags & DebugFlag::INCLUDE_DEBUG_MESSAGE),
197+
DebugFlag::INCLUDE_TRACE => (bool) ($debug_flags & DebugFlag::INCLUDE_TRACE),
198+
DebugFlag::RETHROW_INTERNAL_EXCEPTIONS => (bool) ($debug_flags & DebugFlag::RETHROW_INTERNAL_EXCEPTIONS),
199+
DebugFlag::RETHROW_UNSAFE_EXCEPTIONS => (bool) ($debug_flags & DebugFlag::RETHROW_UNSAFE_EXCEPTIONS),
200+
])),
201+
'#description' => $this->t("It is recommended to disable all debugging in production. During development you can enable the information that you need above."),
189202
];
190203

191204
$form['actions'] = [
@@ -231,6 +244,9 @@ public function validateForm(array &$form, FormStateInterface $formState) {
231244
* {@inheritdoc}
232245
*/
233246
public function submitForm(array &$form, FormStateInterface $formState) {
247+
// Translate the debug flag from individual checkboxes to the enum value
248+
// that the GraphQL library expects.
249+
$formState->setValue('debug_flag', array_sum($formState->getValue('debug_flag')));
234250
parent::submitForm($form, $formState);
235251

236252
$schema = $formState->getValue('schema');

src/GraphQL/Resolver/Composite.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\graphql\GraphQL\Resolver;
44

55
use Drupal\graphql\GraphQL\Execution\FieldContext;
6-
use GraphQL\Deferred;
6+
use GraphQL\Executor\Promise\Adapter\SyncPromise;
77
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
88
use Drupal\graphql\GraphQL\Execution\ResolveContext;
99
use GraphQL\Type\Definition\ResolveInfo;
@@ -44,7 +44,7 @@ public function resolve($value, $args, ResolveContext $context, ResolveInfo $inf
4444
while ($resolver = array_shift($resolvers)) {
4545
$value = $resolver->resolve($value, $args, $context, $info, $field);
4646

47-
if ($value instanceof Deferred) {
47+
if ($value instanceof SyncPromise) {
4848
return DeferredUtility::returnFinally($value, function ($value) use ($resolvers, $args, $context, $info, $field) {
4949
return isset($value) ? (new Composite($resolvers))->resolve($value, $args, $context, $info, $field) : NULL;
5050
});

src/GraphQL/Resolver/Condition.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Drupal\graphql\GraphQL\Execution\FieldContext;
66
use Drupal\graphql\GraphQL\Execution\ResolveContext;
77
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
8-
use GraphQL\Deferred;
8+
use GraphQL\Executor\Promise\Adapter\SyncPromise;
99
use GraphQL\Type\Definition\ResolveInfo;
1010

1111
/**
@@ -45,7 +45,7 @@ public function resolve($value, $args, ResolveContext $context, ResolveInfo $inf
4545
}
4646
}
4747

48-
if ($condition instanceof Deferred) {
48+
if ($condition instanceof SyncPromise) {
4949
return DeferredUtility::returnFinally($condition, function ($cond) use ($branches, $resolver, $value, $args, $context, $info, $field) {
5050
array_unshift($branches, [$cond, $resolver]);
5151
return (new Condition($branches))->resolve($value, $args, $context, $info, $field);

src/GraphQL/Resolver/DefaultValue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Drupal\graphql\GraphQL\Execution\FieldContext;
66
use Drupal\graphql\GraphQL\Execution\ResolveContext;
77
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
8-
use GraphQL\Deferred;
8+
use GraphQL\Executor\Promise\Adapter\SyncPromise;
99
use GraphQL\Type\Definition\ResolveInfo;
1010

1111
/**
@@ -57,7 +57,7 @@ public function resolve(
5757
return $this->default->resolve($value, $args, $context, $info, $field);
5858
}
5959

60-
if ($result instanceof Deferred) {
60+
if ($result instanceof SyncPromise) {
6161
return DeferredUtility::returnFinally($result, function ($current) use ($value, $args, $context, $info, $field) {
6262
if ($current === NULL) {
6363
return $this->default->resolve($value, $args, $context, $info, $field);

src/GraphQL/Utility/DeferredUtility.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\graphql\GraphQL\Utility;
44

55
use GraphQL\Deferred;
6+
use GraphQL\Executor\Promise\Adapter\SyncPromise;
67
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
78

89
class DeferredUtility {
@@ -35,7 +36,7 @@ public static function promiseAdapter() {
3536
* @return mixed
3637
*/
3738
public static function applyFinally($value, callable $callback) {
38-
if ($value instanceof Deferred) {
39+
if ($value instanceof SyncPromise) {
3940
// Recursively apply this function to deferred results.
4041
$value->then(function ($inner) use ($callback) {
4142
return static::applyFinally($inner, $callback);
@@ -52,14 +53,12 @@ public static function applyFinally($value, callable $callback) {
5253
* @param mixed $value
5354
* @param callable $callback
5455
*
55-
* @return \GraphQL\Deferred|mixed
56+
* @return \GraphQL\Executor\Promise\Adapter\SyncPromise|mixed
5657
*/
5758
public static function returnFinally($value, callable $callback) {
58-
if ($value instanceof Deferred) {
59-
return new Deferred(function () use ($value, $callback) {
60-
return $value->then(function ($value) use ($callback) {
61-
return $callback($value);
62-
});
59+
if ($value instanceof SyncPromise) {
60+
return $value->then(function ($value) use ($callback) {
61+
return $callback($value);
6362
});
6463
}
6564

@@ -85,7 +84,7 @@ public static function waitAll(array $values) {
8584
return new Deferred(function () use ($values) {
8685
$adapter = static::promiseAdapter();
8786
return $adapter->all(array_map(function ($value) use ($adapter) {
88-
if ($value instanceof Deferred) {
87+
if ($value instanceof SyncPromise) {
8988
return $adapter->convertThenable($value);
9089
}
9190

@@ -108,7 +107,7 @@ public static function waitAll(array $values) {
108107
*/
109108
public static function containsDeferred(array $values) {
110109
foreach ($values as $value) {
111-
if ($value instanceof Deferred) {
110+
if ($value instanceof SyncPromise) {
112111
return TRUE;
113112
}
114113
}

tests/src/Traits/DataProducerExecutionTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\Tests\graphql\Traits;
44

55
use Drupal\graphql\GraphQL\Execution\FieldContext;
6-
use GraphQL\Deferred;
6+
use GraphQL\Executor\Promise\Adapter\SyncPromise;
77
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
88
use Prophecy\Argument;
99

@@ -35,7 +35,7 @@ protected function executeDataProducer($id, array $contexts = []) {
3535
$context->hasContextValue(Argument::any())->willReturn(FALSE);
3636

3737
$result = $plugin->resolveField($context->reveal());
38-
if (!$result instanceof Deferred) {
38+
if (!$result instanceof SyncPromise) {
3939
return $result;
4040
}
4141

0 commit comments

Comments
 (0)