https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5#.ecuh3j2md
The gist of it is the server will receive the following query:
{
id: < query ID >,
variables: < variables >,
}
and will need to transform it to:
{
query: < print(GraphQL document) >,
variables: < variables >
}
using a json dictionary that is produced by the client.
Open questions on my side:
I'm already working on this (in a private branch), along with a some refactoring to cleanly insert it. It's actually slated for absinthe_plug vs absinthe (as it pre-fetches the document), and it goes beyond what you're hinting at here -- there are some interesting things we can do with pre-running a portion of the pipeline at compilation. You'll see movement on this in the next few days.
@bruce I'm not sure if this has been merged already but that sounds awesome. It would be great to discuss some of the improvements you mention and see if those could be implemented within the persistgraphql tool.
@Poincare Thanks! Likewise, we were excited to see one of the client libraries/frameworks really move forward on an implementation. We've talked about this type of problem as part of our roadmap for awhile, and the progress with Apollo helped give us the clarity we needed to get it done.
It will be merged and released soon; likely as part of our v1.3.0 rollout (this week?). You can see the implementation here: https://github.com/absinthe-graphql/absinthe_plug/pull/53
A fully functional example of support for Apollo's persisted queries boils down to...
Defining a document provider:
defmodule MyApp.ExtractedQueryProvider do
use Absinthe.Plug.DocumentProvider.Compiled
provide File.read!("/path/to/extracted_queries.json")
|> Poison.decode!
|> Map.new(fn {k, v} -> {v, k} end) # invert key/value
end
Then adding that document provider to the initialization of the plug:
plug Absinthe.Plug,
schema: MyApp.Schema,
document_providers: [
Absinthe.Plug.DocumentProvider.Default,
MyApp.ExtractedQueryProvider
]
Then, any documents present in extracted_queries.json will be compiled into the Elixir module at build-time, after being parsed, converted into our intermediate representation, and run through a number of validations (the failure of any of which would cause an build failure). Requests are handled just as in the blog post (lookup up via an "id" parameter) -- but can skip the initial processing they've already completed.
Implemented in absinthe-graphql/absinthe_plug#53, released in absinthe_plug v1.3.0-alpha.0.
Most helpful comment
I'm already working on this (in a private branch), along with a some refactoring to cleanly insert it. It's actually slated for absinthe_plug vs absinthe (as it pre-fetches the document), and it goes beyond what you're hinting at here -- there are some interesting things we can do with pre-running a portion of the pipeline at compilation. You'll see movement on this in the next few days.