-
Notifications
You must be signed in to change notification settings - Fork 157
[Prototype] Server-side query caching #17
Comments
Top level specifications to implement caching for GraphQL with Varnish.Use Magento’s existing caching strategies an extend them to let them also work for the GraphQL requests. GraphQL moves all its logic to the content of the response and moves away from the HTTP nature of the request, this can introduce compatibility issues with other transport protocols: GraphQL subscriptions over web sockets for example. Although, it can be argued that implementing a HTTP-only caching layer is good-enough. The easiest way to implement a caching layer is to handle the /graphql query requests as a normal GET requests (and handle the mutation requests as a POST): The advantage of this strategy is that it is relatively straightforward to implement with Varnish (as the complete request is cached), while still being more fine-grained than caching a complete page (multiple queries will probably be executed per page load). With this setup we do not introduce any new dependencies. We use existing libraries/systems (every should should use varnish anyway). This means that there is almost zero overhead for new developers to implement proper caching. If the cache tag flush works properly there should never be any stale data. You are unable to use a library like https://www.apollographql.com/docs/link/links/batch-http.html. With such a library a lot of cache misses could disappear, as it is highly likely that private queries are sent with public ones. The argument could be made that this library is deprecated because of the face of http/2. A more specialized solution would be a GraphQL-aware caching layer, which is comparable to Apollo Engine which can for example cache the public parts of a query. This is probably more complex to implement and might be a nice V2 version of the caching layer. |
Thanks Paul for your thoughts on this topic! I'll have our technical folks take a look at your suggestions. |
@paliarush I didn't explicitly meant that we should switch to GET requests directly, but it seems that is easily possible as well by providing a custom fetch method to the apollo-link-http library: Might be easier then if Varnish requires additional libraries to get everything up-and-running. |
Varnish:
http://magento.api/graphql?query={queryName{fieldName}}
. The whole query goes to the URLUse cases that should be supported
Prototype
https://github.com/magento/graphql-ce/tree/GraphQL-Cache-Prototype
Has the following concepts tested:
Considered alternatives
The text was updated successfully, but these errors were encountered: