-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.x] Make GET requests cacheable #1196
Comments
Makes sense to me. https://graphql.org/learn/serving-over-http/ explains how to use GET requests, I think we only use POST requests at jobiqo with our Apollo frontend stack. We only use GET requests for persisted queries. I'm thinking about security implications regarding GET requests and CSRF. You must not allow mutations through GET requests, but maybe that is not enforced? Probably unrelated to this issue since this is only about caching GET request responses. Our protection against CSRF is using JWT for authentication, which the browser does not send along automatically like a cookie. |
I agree re preventing mutations, I guess we could check for |
Following! I also noticed this when doing a performance audit. I'm considering configuring Apollo with |
Looking into this a bit more, I believe
...with maybe some testing to the global max age and maybe cacheable metadata is collected/applied to internal caches like page_cache or dynamic_page_cache? |
The above worked for me and I was able to get caching working, one thing though, the current user producer adds a cacheable dependency on the current user which turns into a max-age 0 because the current user proxy isn't a cacheable dependency, instead of adding the cache context for user.
|
I almost feel that core should throw an exception there instead of setting it to zero. |
Yeah agreed, they could just add the type hint to the method. I'd support that given finding max-age = 0's isn't always the easiest thing for people to debug. |
Another issue here, if you're trying to make caching work for authenticated users then dynamic page cache will need to know that the url query arguments are cache contexts. I added this to my schema but it will need to be added in
Without this, all follow-on requests after your first cached response will return the same result. |
Yeah we got around that in our producer - but I think it would be good to try and address that globally in graphql. Needs work for that I think |
Problem statement
At present all GET requests end up with the following HTTP Header:
This is because the route-provider sets
no_cache: TRUE
However, we go to the effort of collecting
CacheableMetadata
throughout the whole resolver pipeline and even make sure to returnCacheableJsonResponse
objects fromRequestController
Whilst this is used for the results cache, it isn't used at the response level because as soon as you add
no_cache: TRUE
-\Drupal\Core\PageCache\ResponsePolicy\DenyNoCacheRoutes
kicks in and sets the cache-policy to DENY.This is evaluated in
\Drupal\Core\EventSubscriber\FinishResponseSubscriber::onRespond
and as soon as it finds something that is not cacheable, it sets this HTTP Header, which effectively means any use of GET for queries can't be cached in a CDN.Proposed resolution
page_cache_response_policy
too.If this sounds acceptable, let me know and I'll work on a pull-request
The text was updated successfully, but these errors were encountered: