envelop icon indicating copy to clipboard operation
envelop copied to clipboard

Plugin idea: Apollo-compat Automatic Persisted Query

Open cometkim opened this issue 4 years ago • 6 comments

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

cometkim avatar Jul 27 '21 13:07 cometkim

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.

ccollie avatar Aug 08 '21 16:08 ccollie

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.

ccollie avatar Aug 14 '21 22:08 ccollie

Also, despite the name, the code can equally handle mutations. Should we restrict to query to maintain parity with apollo-client ?

ccollie avatar Aug 14 '21 22:08 ccollie

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

cometkim avatar Aug 15 '21 10:08 cometkim

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 ?

ccollie avatar Aug 18 '21 04:08 ccollie

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

PabloSzx avatar Aug 24 '21 22:08 PabloSzx

Closing in favour of the built-in Automatic Persisted Queries plugin in GraphQL Yoga v3 🎉

YassinEldeeb avatar Dec 09 '22 07:12 YassinEldeeb