Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 370cdad

Browse files
author
Alex Langenfeld
committed
update README
1 parent 5c77ce3 commit 370cdad

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ The `graphqlHTTP` function accepts the following options:
5353
* **`graphiql`**: If `true`, may present [GraphiQL][] when loaded directly
5454
from a browser (a useful tool for debugging and exploration).
5555

56+
* **`loadPersistedDocument`**: A function that takes an input id and returns a
57+
valid Document. If provided, this will allow your GraphQL endpoint to execute
58+
a document specified via `documentID`.
59+
60+
* **`persistValidatedDocument`**: A function that takes a validated Document and
61+
returns an id that can be used to load it later. This is used in conjunction
62+
with `loadPersistedDocument`. Providing this function will enable persisting
63+
documents via the `document` parameter at the `/persist` subpath. It is
64+
recommended that this option only be enabled in development deployments.
65+
5666

5767
## Debugging
5868

@@ -156,6 +166,22 @@ new GraphQLObjectType({
156166
});
157167
```
158168

169+
## Persisted Documents
170+
171+
Putting control of the query in to clients hands is one of the primary benefits
172+
of GraphQL. Though when this is deployed to production naively, it is possible to
173+
end up uploading and revalidating the same document text across all clients of a
174+
particular deployment. It can even be problematic within a single client, sending
175+
the exact same query repeatedly. Uploading and validating a large GraphQL document
176+
can be very costly, especially over a poor network connection from a mobile device
177+
with something large and complex such as Facebook's News Feed GraphQL query.
178+
179+
One solution to this problem that was developed early in the use of GraphQL at
180+
Facebook was persisted documents. At build time, we take the GraphQL document and
181+
persist it on the server getting back an ID. Then at runtime, we only upload the
182+
ID of the document and the variables. When the server receives this request, it
183+
loads the query and executes it, knowing it was already validated.
184+
159185
[`graphql-js`]: https://github.com/graphql/graphql-js
160186
[`formatError`]: https://github.com/graphql/graphql-js/blob/master/src/error/formatError.js
161187
[GraphiQL]: https://github.com/graphql/graphiql

0 commit comments

Comments
 (0)