It is Mercurius job to group GraphQL types by handler instance #1113
Closed
oceanmotive
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
That case is uncommon: you have 3 entities that are essentially aliases of each other. We don't want to handle this automatically, because detecting this is pretty hard. You can always implement the dataloader pattern yourself, there is nothing really specific of our implementation. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
at the company I am working for,
we have GraphQL interface like Animal,
and seven GraphQL types which are implementation of Animal - Dog, Cat, Fish, ....
and we have dataloaders to load part of fields of every Animal
like
const dataloaderFunc = (...) => ...
{ // this is a dataloader definition which then will be loaded into mercurius plugin
Dog : dataloaderFunc,
Cat : dataloaderFunc,
Fish : dataloaderFunc,
...
}
I.e. for every Dog,Cat,Fish.. we want the same dataloader to be used
And we have a query which gives us an overview of all Animals, like
allAnimals() {
color : ...
voice : ... // other fields of that interface
}
What happens internally is that mercurius gets all Animals, they are of different types (Dog, Cat, Fish, ...),
group them by type, and pass each group to the respective dataloaderFunc.
So if we have in the resulte set 5 Dogs, 2 Cats and 3 Fish, there will be 3 calls of dataloaderFunc, each with the respective set.
What I am implying here is that (look at the above) I wanted for mix of Dogs,Cats,Fishes... to be passed into dataloaderFunc via single call.
It is not only the same expression( * : dataloaderFunc ), but also the same instance (dataloaderFunc).
Instead, I get something that goes against purpose of dataloaders (solve N+1 problem); I have got multiple calls of dataloaderFunc when they might be combined into one.
I think that when Mercurius starts, it might make a check of dataloaders to check what types should be grouped based on equality of the respective dataloaders.
Beta Was this translation helpful? Give feedback.
All reactions