Apollo-client: Persisted queries

Created on 28 Jul 2016  路  5Comments  路  Source: apollographql/apollo-client

From this PR to express-graphql, it is evident that there is interest around support for persisted/stored queries on GraphQL server implementations and it would be great if Apollo Client could support this feature right out of the box.

I'll use this issue to sketch out a preliminary design for this feature and how we should implement it internally.

Implementation

The bulk of the changes needed to support persisted queries are at the NetworkInterface level. Specifically, here's what we have to do:

  • Maintain a query lookup table within the NetworkInterface that maps from hashes of query documents to the persisted query ids returned by a server that supports persisted queries
  • Every time query is called within the NetworkInterface, it should hash the query document and check the map described above.
  • If the hash is a key of the map, then we simply send the query ID associated with that hash to the server as a documentId.
  • If the hash is not a key of the map, we send the query to /persist, introduce the hash and the returned id and then send that id to the /graphql endpoint as documentId. Another option would be to just send the entire query to the /graphql endpoint and also send the entire query to /persist simultaneously so that we don't fire two sequential network requests.

Notice that this solves the problem of using persisted queries on a per-client basis, not across multiple clients. It also has no knowledge of what queries the server already knows about. These goals can be attacked with static analysis, etc. of some kind and will probably be the "v2" of persisted queries support.

馃ウ low-priority

Most helpful comment

To clarify I think the plan is to wait for the express GraphQL pr to land before moving forward with this implementation.

All 5 comments

To clarify I think the plan is to wait for the express GraphQL pr to land before moving forward with this implementation.

Related: #264

@stubailo @Poincare @helfer I'm open to work on this as expressed before on slack, I think this is an important feature to get production-grade GraphQL. Since the "reference" PR isn't moving forward, I want to see if we can push our own implementation. I'm going to open an umbrella issue to track progress on this.

We finally have an implementation of this through extractgql and it lives outside of Apollo Client entirely - can we close this issue at this point? @helfer

Is someone using approach: on dev environment support mix(persisted queries & arbitrary queries) and on prod environment support only persisted queries?

Was this page helpful?
0 / 5 - 0 ratings