graphql-kotlin allows you to abstract the schema generation and data fetching code, you may not even need data loaders if instead you have some persistant cache on your server.
If you still want to use data loaders though, they are supported through the common interfaces.
The GraphQLRequestHandler accepts an optional
DataLoaderRegistryFactory that will be used on every request.
DataLoaderRegistryFactory generates a new
DataLoaderRegistry on every request. The registry is a map of a unique data loader names to a
DataLoader object that handles the cache for an output type in your graph.
DataLoader caches the types by some unique value, usually by the type id, and can handle different types of batch requests.
To help in the registration of these various
DataLoaders, we have created a basic interface
This allows for library users to still have full control over the creation of the
DataLoader and its various configuraiton options,
but then allows common server code to handle the registration, generation on request, and execution.
graphql-kotlin-server includes a helpful extension function on the
DataFetchingEnvironment so that you can easily retrieve values from the data loaders in your schema code.
Because the execution of data loaders is handled by
graphql-java, which runs using
CompletionStage, currently we can
suspend functions when envoking data loaders. Instead, return the
CompletableFuture directly from the
response in your schema functions. See issue #986.