How to leverage HTTP caching via GraphQL

Hello.

I’m looking to leverage HTTP caching to reduce roundtrip latency on some of our fauna queries.
However, this would require that my HTTP requests are GET and not POST

Many GraphQL guides say that GraphQL is also available via GET, by providing the GraphQL query in the query string.

However when I try to use GET instead of POST - Fauna returns me an error: “Invalid endpoint or method.”

Is there any way to get it to respond to GET requests? Is this planned?

Unfortunately, GET support does not exist in the Fauna GraphQL API. Since connections are made via HTTPS, proxies have no opportunity to cache responses.

The GraphQL API does not cache results for you because the cache could be invalid compared to the current state of the database. If we had a cache that was kept up-to-date, there would be little to no practical benefit over current performance.

You might be able to configure your own cache solution by using Apollo Client.

I’d like to piggyback on this thread and ask, does TanStack (Formerly React Query) work as a good alternative to Apollo Client? I’ve been debating which to use, or honestly not sure if they should be used together? Any insight you have would be appreciated!

I think that depends whether or not the HTTPS connection is terminated at your proxy - that’s the case for e.g. Fastly’s Compute@Edge service.

It would be nice to consider allowing GET requests to FaunaDB, considering they’re part of the GraphQL spec and everything.

Either way, thanks for the heads up.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.