@@ -302,47 +302,33 @@ option to configure a name extracting function along with `Class` to GraphQL Obj
302302name mappings that should help to cover more corner cases.
303303
304304
305+ [[execution-graphqlsource-operation-caching]]
306+ ==== Operation Caching
305307
306- [[execution-graphqlsource-preparsed-document-provider]]
307- ==== PreparsedDocumentProvider
308+ GraphQL Java must _parse_ and _validate_ an operation before executing it. This may impact
309+ performance significantly. To avoid the need to re-parse and validate, an application may
310+ configure a `PreparsedDocumentProvider` that caches and reuses Document instances. The
311+ {graphql-java-docs}/execution/#query-caching[GraphQL Java docs] provide more details on
312+ query caching through a `PreparsedDocumentProvider`.
308313
309- Before operations can be executed by GraphQL Java, their request string must be _parsed_ and _validated_. These
310- two steps may impact the performance of applications significantly.
311-
312- You may configure a `PreparsedDocumentProvider` using `GraphQlSource.Builder#configureGraphQl`. The
313- `PreparsedDocumentProvider` can intercept these two steps and gives library consumers the tools to
314- cache, or modify the resulting operation.
315-
316- The following snippet uses https://github.com/ben-manes/caffeine[Caffeine] to build a `PreparsedDocumentProvider`
317- which caches the 2500 most recent operations for a maximum of 1 hour:
314+ In Spring GraphQL you can register a `PreparsedDocumentProvider` through
315+ `GraphQlSource.Builder#configureGraphQl`:
316+ .
318317
319318[source,java,indent=0,subs="verbatim,quotes"]
320319----
321- public class CachingPreparsedDocumentProvider implements PreparsedDocumentProvider {
322-
323- private final Cache<String, PreparsedDocumentEntry> cache = Caffeine
324- .newBuilder()
325- .maximumSize(2500)
326- .build();
320+ // Typically, accessed through Spring Boot's GraphQlSourceBuilderCustomizer
321+ GraphQlSource.Builder builder = ...
327322
328- @Override
329- public PreparsedDocumentEntry getDocument(ExecutionInput executionInput,
330- Function<ExecutionInput, PreparsedDocumentEntry> parseAndValidateFunction) {
331- return cache.get(executionInput.getQuery(), operationKey -> parseAndValidateFunction.apply(executionInput));
332- }
323+ // Create provider
324+ PreparsedDocumentProvider provider = ...
333325
334- }
326+ builder.schemaResources(..)
327+ .configureRuntimeWiring(..)
328+ .configureGraphQl(graphQLBuilder -> graphQLBuilder.preparsedDocumentProvider(provider))
335329----
336330
337- Please note that caching in the preceding snippet only works when you parameterize your operation using variables:
338- [source,graphql,indent=0,subs="verbatim,quotes"]
339- ----
340- query HelloTo($to: String!) {
341- sayHello(to: $to) {
342- greeting
343- }
344- }
345- ----
331+
346332
347333[[execution-reactive-datafetcher]]
348334=== Reactive `DataFetcher`
@@ -466,7 +452,7 @@ problem.
466452
467453GraphQL Java provides a `DataLoader` mechanism for batch loading of related entities.
468454You can find the full details in the
469- https://www. graphql-java.com/documentation/v16 /batching/[GraphQL Java docs]. Below is a
455+ { graphql-java-docs} /batching/[GraphQL Java docs]. Below is a
470456summary of how it works:
471457
472458 1. Register ``DataLoader``'s in the `DataLoaderRegistry` that can load entities, given unique keys.
0 commit comments