Comments (4)
Have a look CompleteableFuture.thenCompose
Its effectively a flatmap
on two CFs that means you get to chain together to steps that both produce CFs and present one
Also I think you need to change the data fetchers so that instead of wrapping them in AsyncDataFetcher.async()
you code them to use the CompleteableFuture.supplyAsync
DataFetcher dataFetcher = new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
Supplier<String> fetchOfValue = new Supplier<String>() {
@Override
public String get() {
return "This is done async via a supplier and CompletableFuture.supplyAsync";
}
};
return CompletableFuture.supplyAsync(fetchOfValue);
}
};
HOWEVER....
if you are using DataLoader then typically you DONT need async data fetchers because the org.dataloader.BatchLoader
is itself ready for an async value
Your BatchLoader of books should use CompletableFuture.supplyAsync
and hence there is no need for AsyncDataFetcher.async
to be used
from java-dataloader.
Thank you for your answer.
In fact, my project is a common project.
We abstract the MODEL
and DATASOURCE
.
MODEL
like VOs, use by front-end
such as web or app; and DATASOURCE
like BOs, fetch data from database or other rpc.
Dataloader
take charge of batch load and cache a DATASOURCE
.
A fetcher will returns a MODEL, but MODEL may from two DATASOURCE or more, even use DAG to process DATASOURCE dependency.
So a fetcher may consume a long time. It's why I use AsyncDataFetcher.async
to get a fetcher.
Back to this question, I think your first suggest apply to two CFs serializability , such as flapMap. but this fact is CF1<CF2>, the CF1
produce AsyncDataFetcher.async
Fetchers , the CF2
product dataloader.load in the Fetchers.
And the 2nd suggest async in fetcher of Supplier
, or use AsyncDataFetcher.async is no difference I think. because I want async fetcher and dataloader.load is async to wait graphql execution to dispatchAll() also.
Of course, my question is not only belong to dataloader. It's a graphql-java Invocation process question. But it's bring by dataloader, so we discuss it in here.
from java-dataloader.
Let me be more explicit.
When you use DataLoader you are trying to "batch" N calls by key to one batch load function.
Therefore your data fetchers should be just like
DataFetcher df = env -> {
return dataLoader.load(ev.getArg("myKey)
}
This will return a CF that is not resolved until dispatch is called and the batch load function is invoked
In your BatchLoad function you should do this
BatchLoader<K,V> batchLoader = keys -> {
return CompleteableFuture.supplyAsync( () -> {
return thisCallMakeTakeSomeTime(keys);
});
}
This will be 100% async . There is no need for AsyncDataFectcher etc... at the field data fetcher site.
from java-dataloader.
Yeah, so I think the dataloader will above of DAG fetcher
Thx~
from java-dataloader.
Related Issues (20)
- invalid automatic module name when used with Java modules
- Version 3.0.0 and later is no OSGi bundle anymore HOT 2
- Automatic Module Name clashes with graphql-java Module HOT 2
- Add ReactiveStreams and Kotlin Coroutines variants for DataLoader HOT 1
- Support Flow or Channel as Subscription return type HOT 1
- Failed to build.gradle HOT 1
- Querying for length of dataloader queue HOT 2
- Avoid allocations when dataloader has no work
- ScheduledDataLoaderRegistry.newScheduledRegistry() creates new ScheduledExecutorService on every invocation
- ScheduledDataLoaderRegistry can leak scheduler threads HOT 1
- When dispatchPredicate condition evaluates to false, shouldDispatch should return false HOT 3
- How to let BatchLoader know the columns of current DataFetchingEnvironment?
- Make the DataLoaderRegistry use a supplier pattern HOT 5
- the `synchronized` in DataLoader
- How to wrap Caffeine with CacheMap? HOT 6
- Is the data loader's per-key context allowed to be null?
- Java DataLoader: Mismatches results HOT 1
- Null pointer in dispatchQueueBatch v2.1.1 HOT 1
- ValueCache: batch function isn't always triggered on cache miss HOT 5
- DataLoader 3.x will not be upgraded in graphql-java 17.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-dataloader.