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

org.rapidgraphql.dataloaders.GraphQLBatchLoader Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy