New Exhaustion based data loader dispatching strategy by andimarek · Pull Request #4130 · graphql-java/graphql-java

This PR introduces an alternative data loader strategy that mimics in some way how the JS event loop Data Loader dispatcher works:

Instead of dispatching per Level (the current default) this strategy dispatches as soon as the engine is not "busy" anymore.

Busy here means specifically:

  • No sub selection is currently being fetched (on any level
  • No completion is currently executed
  • No Data Loader is currently dispatched

This also handles "chained data loaders": data loaders being used after another data loader inside one DataFetcher.

This new dispatching strategy can be enabled by setting

  graphQLContext.put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, true);

or

 GraphQL.unusualConfiguration(graphqlContext).dataloaderConfig().enableDataLoaderExhaustedDispatching(true)