cc.voox.graphql.IDataLoader Maven / Gradle / Ivy
package cc.voox.graphql;
import org.dataloader.DataLoader;
import org.dataloader.Try;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public interface IDataLoader {
default DataLoader get() {
return DataLoader.newDataLoader(keys -> CompletableFuture.supplyAsync(() -> handle(keys)));
}
default DataLoader getTry() {
return DataLoader.newDataLoaderWithTry(keys -> CompletableFuture.supplyAsync(() -> handleTry(keys)));
}
default List> handleTry(List keys) {
return keys.stream().map(k -> handleTry(k)).collect(Collectors.toList());
}
default Try handleTry(K k) {
return Try.tryCall(() -> handle(k));
}
List handle(List keys);
V handle(K key);
default boolean useTryMode() {
return false;
}
}