Skip to content

Commit 82cbf59

Browse files
sebas5384fubhy
authored andcommitted
Support cacheable request errors at execution (#642)
1 parent 4e82585 commit 82cbf59

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Drupal\graphql\GraphQL\Cache;
4+
5+
use GraphQL\Server\RequestError;
6+
use Drupal\Core\Cache\CacheableDependencyInterface;
7+
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
8+
9+
/**
10+
* Cacheable Request Error.
11+
*/
12+
class CacheableRequestError extends RequestError implements CacheableDependencyInterface {
13+
use RefinableCacheableDependencyTrait;
14+
}

src/GraphQL/Execution/QueryProcessor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\Core\Session\AccountProxyInterface;
1010
use Drupal\graphql\Plugin\SchemaPluginManager;
1111
use Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface;
12+
use Drupal\graphql\GraphQL\Cache\CacheableRequestError;
1213
use GraphQL\Error\Error;
1314
use GraphQL\Error\FormattedError;
1415
use GraphQL\Executor\ExecutionResult;
@@ -200,6 +201,11 @@ protected function executeOperation(PromiseAdapter $adapter, ServerConfig $confi
200201

201202
return $this->executeUncachableOperation($adapter, $config, $params, $document);
202203
}
204+
catch (CacheableRequestError $exception) {
205+
return $adapter->createFulfilled(
206+
new QueryResult(NULL, [Error::createLocatedError($exception)], [], $exception)
207+
);
208+
}
203209
catch (RequestError $exception) {
204210
return $adapter->createFulfilled(new QueryResult(NULL, [Error::createLocatedError($exception)]));
205211
}

0 commit comments

Comments
 (0)