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
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











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.