facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.4k stars 1.82k forks source link

[modern] Persisted GraphQL Queries in Modern? #2008

Open johntran opened 7 years ago

johntran commented 7 years ago

Since all GraphQL queries are known at build time, I am wondering if I could use the information given by the files generated by relay-compiler to:

  1. Create ID's
  2. Send those ID's to the GraphQL server as a GET/POST: ex GET /graphql?query_id=eyBuaWNl123 or POST /graphql?mutation_id=abcdefgh321
  3. Get a response back equal to what you would normally get from sending in a GraphQL query string.

What would the pseudo code look like for this?

Related: RFC: GraphQL Persisted Documents https://github.com/graphql/express-graphql/pull/109 persistgraphql https://github.com/apollographql/persistgraphql

sibelius commented 7 years ago

There is an open PR about it already

johntran commented 7 years ago

@sibelius

Ah I see, this one right? https://github.com/facebook/relay/pull/1846

staylor commented 7 years ago

Here is how I implement it in Relay and GraphQL, using md5 and Redis

Relay https://github.com/staylor/wp-relay-app/blob/master/src/relay/fetcher.js#L26

GraphQL https://github.com/staylor/wp-graphql/blob/master/src/server.js#L42

I persist the queries when starting the server: https://github.com/staylor/wp-relay-app/blob/master/package.json#L36

Script to persist queries: https://github.com/staylor/wp-relay-app/blob/master/tools/persistedQueries.js

yusinto commented 6 years ago

For a compile time solution, see relay-compiler-plus. The hard work is done for you by this custom compiler at compile time.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.