envelop
envelop copied to clipboard
Plugin idea: Apollo-compat Automatic Persisted Query
I saw a plugin for parse caching is exist, but it would be better if we have plugin that compat with the Apollo's automatic persisted query protocol a.k.a APQ
Spec: https://github.com/apollographql/apollo-link-persisted-queries#apollo-engine Apollo: https://www.apollographql.com/docs/apollo-server/performance/apq/ URQL: https://formidable.com/open-source/urql/docs/advanced/persistence-and-uploads/#automatic-persisted-queries
I needed this for a project, so I started taking a stab on an implementation based on Mercurius. If I have time in the next few days I'll do some cleanup and post my repo.
Quick question. Would it be useful to have a distributed cache for this (like redis), or would in-memory suffice. I'm supporting the simplest case since currently the former is not possible afaics since onParse is synchronous only.
Also, despite the name, the code can equally handle mutations. Should we restrict to query to maintain parity with apollo-client ?
I'm using some in-memory LRUs and some MongoDB in production. Obviously, this asynchronous situation is needed, but there is still an ongoing discussion about it.
See https://github.com/dotansimha/envelop/discussions/497
Here's my initial implementation:
https://github.com/ccollie/envelop/commit/35918f1a75a0e3bfe7cd4684637ff7107c535874
The issue is that per protocol, query can be undefined
https://github.com/apollographql/apollo-link-persisted-queries#apollo-engine
so there's no good way (that I know of) for me to test that scenario. The work is done in onParse which requires a defined source
Any suggestions ?
Already available for graphql-ez 🎉 (which uses Envelop at it's core, it just hasn't been fully announced yet) https://www.graphql-ez.com/plugins/automatic-persisted-queries
thank you @ccollie
Closing in favour of the built-in Automatic Persisted Queries plugin in GraphQL Yoga v3 🎉