create-graphql-server
create-graphql-server copied to clipboard
Dataloader does not key on mongo ids properly
Two different identical mongo ids (i.e. the same id reached in two different ways) will not have equality in JS and thus will be separate keys in the data loader.
The effect of this is:
- unnecessary queries
- if you clear a key (e.g. on update) you may not see the changes (if you are reading from the other key).
I think the simplest solution is to use: { cacheKeyFn id => id.toString() } when creating data loaders.
this package could help https://github.com/entria/graphql-mongoose-loader#mongoose-dataloader-batch