-
Notifications
You must be signed in to change notification settings - Fork 202
Description
#487 allowed page caching GraphQL requests.
As far as I can see this only applies to GET requests since Drupal's \Drupal\Core\PageCache\DefaultRequestPolicy uses the \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod() rule which eventually decides in \Symfony\Component\HttpFoundation\Request::isMethodCacheable() that only GET and HEAD requests are cacheable.
I would like to cache GraphQL POST requests in one of my projects. I was able to achieve this by swapping out \Drupal\Core\PageCache\DefaultRequestPolicy with a custom implementation that extends \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod(), explicitely allowing caching GraphQL POST requests, as such:
/**
* {@inheritdoc}
*/
public function check(Request $request) {
if (!$this->isCli() && $request->getMethod() === 'POST' && $request->attributes->has('_graphql')) {
return static::ALLOW;
}
return parent::check($request);
}
Has anyone already tried doing the same? Perhaps in a different way? Any potential issues I should be wary of?
Is this a feature that might be worth looking into adding to the GraphQL module, especially since POST is more or less the default behaviour in GraphQL?