Skip to content
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

Using dataloader at leaf level of multi layer schema failed to batch #276

Open
Tracked by #297
xavier-taylor opened this issue Jul 20, 2021 · 0 comments
Open
Tracked by #297

Comments

@xavier-taylor
Copy link

xavier-taylor commented Jul 20, 2021

Hi there,

I have a graphql schema like this:
D has many S has many SW has one W has many C.
D is available via a root level query.
(The underlying SQL has the same set of entities and relationships between them).

Using apollo server (not sure if relevant), postgres and knex.

I started by adding a dataloader for C. I then made a root level query for D, asking for all the properties of each element in the above schema. Testing revealed that the caching worked - each distinct C was only queried for once. But batching didn't work - for each distinct C, there was a separate SELECT.

When debugging this, added batchScheduleFn: (callback) => setTimeout(callback, 100) to the dataloader for C. At that point, batching started to work.

This made me think that somehow the C resolution was taking place on different event loop tics. On a hunch, I added a dataloader for W, SW and S. (none for D, as there is just one root level query for D).

After doing this, batching worked for all of S, SW, W and C - even with the batchSchedule function removed.

So I wanted to ask - is this possibly a bug (either in dataloader or, for a separate matter, Apollo Server), or is it expected that batching at the leaf node C would not work unless all ancestor nodes are also resolved with dataloaders?

If this isn't a bug, I wonder if adding this information to the documentation would be possible, to help other people who find themselves in this situation - implementing dataloader only at the leaf of a deep schema, and having batching not work they way they expected it would?

Anyhow, thanks for the library and its ongoing maintenance :)

@saihaj saihaj mentioned this issue Mar 11, 2022
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant