@@ -53,6 +53,16 @@ The `graphqlHTTP` function accepts the following options:
53
53
* ** ` graphiql ` ** : If ` true ` , may present [ GraphiQL] [ ] when loaded directly
54
54
from a browser (a useful tool for debugging and exploration).
55
55
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
+
56
66
57
67
## Debugging
58
68
@@ -156,6 +166,22 @@ new GraphQLObjectType({
156
166
});
157
167
```
158
168
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
+
159
185
[ `graphql-js` ] : https://github.com/graphql/graphql-js
160
186
[ `formatError` ] : https://github.com/graphql/graphql-js/blob/master/src/error/formatError.js
161
187
[ GraphiQL ] : https://github.com/graphql/graphiql
0 commit comments