All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.execution.instrumentation.dataloader.FallbackDataLoaderDispatchStrategy Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.execution.instrumentation.dataloader;

import graphql.Internal;
import graphql.execution.DataLoaderDispatchStrategy;
import graphql.execution.ExecutionContext;
import graphql.schema.DataFetcher;


/**
 * Used when the execution strategy is not an AsyncExecutionStrategy: simply dispatch always after each DF.
 */
@Internal
public class FallbackDataLoaderDispatchStrategy implements DataLoaderDispatchStrategy {

    private final ExecutionContext executionContext;

    public FallbackDataLoaderDispatchStrategy(ExecutionContext executionContext) {
        this.executionContext = executionContext;
    }


    @Override
    public DataFetcher modifyDataFetcher(DataFetcher dataFetcher) {
        return (DataFetcher) environment -> {
            Object obj = dataFetcher.get(environment);
            executionContext.getDataLoaderRegistry().dispatchAll();
            return obj;
        };

    }
}