org.rapidgraphql.dataloaders.GraphQLBatchLoader Maven / Gradle / Ivy
package org.rapidgraphql.dataloaders;
import org.dataloader.BatchLoader;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
public abstract class GraphQLBatchLoader extends AbstractGraphQLBatchLoader implements BatchLoader {
/**
* This method is called by DataLoader framework to load batch of entities
* We recommend to implement synchronous variant of this: loadSync
* @param keys the collection of keys to load
*
* @return a promise of the values for those keys in the same order
*/
@Override
public CompletionStage> load(List keys) {
return CompletableFuture.supplyAsync(() -> syncLoad(keys));
}
abstract public List syncLoad(List keys);
@Override
@NotNull
protected DataLoader createNewDataLoader() {
return DataLoaderFactory.newDataLoader(this, getDataLoaderOptions());
}
}