@@ -285,6 +285,46 @@ name mappings that should help to cover more corner cases.
285
285
286
286
287
287
288
+ [[execution-graphqlsource-preparsed-document-provider]]
289
+ ==== PreparsedDocumentProvider
290
+
291
+ Before operations can be executed by GraphQL Java, their request string must be _parsed_ and _validated_. These
292
+ two steps may impact the performance of applications significantly.
293
+
294
+ You may configure a `PreparsedDocumentProvider` using `GraphQlSource.Builder#configureGraphQl`. The
295
+ `PreparsedDocumentProvider` can intercept these two steps and gives library consumers the tools to
296
+ cache, or modify the resulting operation.
297
+
298
+ The following snippet uses https://github.com/ben-manes/caffeine[Caffeine] to build a `PreparsedDocumentProvider`
299
+ which caches the 2500 most recent operations for a maximum of 1 hour:
300
+
301
+ [source,java,indent=0,subs="verbatim,quotes"]
302
+ ----
303
+ public class CachingPreparsedDocumentProvider implements PreparsedDocumentProvider {
304
+
305
+ private final Cache<String, PreparsedDocumentEntry> cache = Caffeine
306
+ .newBuilder()
307
+ .maximumSize(2500)
308
+ .build();
309
+
310
+ @Override
311
+ public PreparsedDocumentEntry getDocument(ExecutionInput executionInput,
312
+ Function<ExecutionInput, PreparsedDocumentEntry> parseAndValidateFunction) {
313
+ return cache.get(executionInput.getQuery(), operationKey -> parseAndValidateFunction.apply(executionInput));
314
+ }
315
+
316
+ }
317
+ ----
318
+
319
+ Please note that caching in the preceding snippet only works when you parameterize your operation using variables:
320
+ [source,graphql,indent=0,subs="verbatim,quotes"]
321
+ ----
322
+ query HelloTo($to: String!) {
323
+ sayHello(to: $to) {
324
+ greeting
325
+ }
326
+ }
327
+ ----
288
328
289
329
[[execution-reactive-datafetcher]]
290
330
=== Reactive `DataFetcher`
0 commit comments