kieraneglin
We’re looking at Phoenix with Absinthe to replace a very high traffic route of a Rails application. We’ve created a proof of concept app that’s performing very well, but it’s been difficult to find documentation on real-world caching for Absinthe.
We use Cloudfront and cannot change this to use a different CDN. We are using POST requests from our Apollo client. We’d like to cache at the CDN level, but we can’t find much information on setting cache control headers per-query. Is there a built in way to approach this? If not, I was thinking of writing a middleware that sends a cache control header per-query name or hash, but I don’t want to do that if there’s an out of box solution.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
POSTis generally considered uncachable, as you do them for side effects.kieraneglin
Fair enough! In that case, what’s the common solution for caching gql responses?
NobbZ
Not using GraphQL.
Cachability is the big downside of GraphQL. Similar discussion as with SOAP apply.
lucaong
As @NobbZ said, GraphQL is not ideal when it comes to caching, especially not with HTTP caching.
A CDN would have to cache POST requests (already a no-go in HTTP, as they are meant for side effects). Also, the benefit of caching the whole query would be limited, as the clients could make slight changes to the query, or request fresh data alongside the cached one, and the whole query will be a cache miss.
There are some approaches to caching partial results server-side, but nothing coming close to the well-established and simple HTTP caching, used by CDNs.
I personally like the flexibility and control over data that GraphQL gives to the client, but when caching is important I use REST. For example, we have REST endpoints for a few high-traffic, cacheable resources, alongside the GraphQL API that serves most of the other needs of the client.
One other possibility worth mentioning is to have a GraphQL API on top of REST endpoints. The GraphQL API would act as the client for the REST endpoint, and would have to take care of caching using HTTP headers.
kieraneglin
That’s too bad! Thank you all for the information.
This seems like a problem that many people would benefit from being solved. I might try my hand at something similar to Apollo where the query is hashed and this hash is sent via a REST get request. If Phoenix is aware of this hash and has the result cached, it returns the cached data with appropriate headers so that CDNs can work with it. If Phoenix doesn’t have this result cached, a second gql request is made that ends up caching the result for the next people that try within the TTL.
The added complexity is less than ideal, but I imagine that it would solve our use case
benwilson512
Keep in mind that you can do graphql queries via GET. If the are just requesting data you can do
?query={hello { world } }&variables=.kieraneglin
Since you’re a bit of an authority on this, I should ask. I’ve read that GET requests are avoided because the payload can be too long for URLs to handle. Is this a legitimate concern or is this information outdated? Because if I can just use GET requests, that’d make life a lot easier.
In other news, I have a proof of concept for Automatic Persisted Queries with customizable cache control headers with Absinthe. I’ll also be playing around with that to see how it feels!
benwilson512
@kieraneglin I’m not doing this myself, but as I understand it folks like Facebook who are doing this at scale use persisted queries such that the front end is doing
query=$hash&variables=, and then you only need to worry about the variables fitting within the GET request limits, which normally should be fine.Definitely interested to see what your automatic persisted queries solution looks like. Absinthe has a behaviour for doing persisted documents, although I think the built in backend for that is only related to queries known at compile time. Nonetheless, it’s a behaviour, so you could absolutely make one that was more dynamic.
jtompl
Apollo seems to have found a nice way how to accomplish server-side caching of GQL queries, even using CDN: Server-Side Caching - Apollo GraphQL Docs .
Not supported by Absinthe yet unfortunately.
benwilson512
The apollo solution is based on directives and middleware, both of which Absinthe has. If someone wants to take a crack at this I’m sure it’d make for a great library, and I’d be happy to make any tweaks to Absinthe that are needed if they run into blockers.