-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] data loader batch load fails when non-data loader function is included among data-loader functions. #285
Comments
Same question. For example:
With
Without
|
@lixurea @hyunhoRIDI This is expected because dataloader only batches requests made in the same event loop tick. #150 |
werid thing is, if I put non-dataloader function behind, dataloader successfully collects the requests within a tick.
this does not work. but
could you confirm this is right @lixurea ? |
@hyunhoRIDI yes, if the data loader function goes first, it successfully batches requests. Not sure why though. @vivek-ng Thanks for the info. I've been reading about event loops, but still not sure what makes it a separate event loop tick? |
@vivek-ng Is there any way to use permissions or authorization guards like directives or GraphQL Shield alongside dataloaders without |
I also asked about this issue here: https://www.reddit.com/r/graphql/comments/1686dmf/dataloaders_graphql_shield_with_apollo_server_and/ |
@lixurea I'm currently having a look at how it works, and found your question. const myFunc = () => {
return new Promise(resolve => {
myDataLoader.load(id).then(result => {
myAsyncFunc().then(resolve)
});
});
} In this case, the code is first waiting at all dataloaders to run and then launches the async function however in the following case: const myFunc = () => {
return new Promise(resolve => {
myAsyncFunc().then(result => {
myDataLoader.load(id).then(resolve)
});
});
} If ran in parallel, the calls to "myAsyncFunc" would not "wait" on each other before scheduling the next step which is to load data and then resolve it. I find the "async await" writing does kind of hide the fact that we add to the promise queue some blocks of codes. I'm basing that explanation on that interesting article and the node event loop |
I am experiencing a weird edge case with data loader.
Suppose we have functions like below.
Let's say there are total three async functions where the first and the last function use dataloader, but second function is just a plain non-dataloader function.
I simply expected that 'firstQueryBatch' and 'thirdQueryBatch' would be called once with batch Ids[](as dataloader should combine parameters) and only calling 'secondQueryNonBatch' three times as it is not a dataloader function.
However, when I debug the output, once it calls 'firstQueryBatch' once successfully, it ended up calling 'secondQueryNonBatch' AND 'thirdQueryBatch' three times. Dataloader fails to combine parameters for 'thirdQueryBatch' and calling it three times with parameters with single item in each array.
['1'], ['2'], then ['3'].
Could anyone explain why this is happening?
The text was updated successfully, but these errors were encountered: