create-graphql-server icon indicating copy to clipboard operation
create-graphql-server copied to clipboard

Dataloader does not key on mongo ids properly

Open tmeasday opened this issue 8 years ago • 1 comments

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:

  1. unnecessary queries
  2. 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.

tmeasday avatar Jul 24 '17 04:07 tmeasday

this package could help https://github.com/entria/graphql-mongoose-loader#mongoose-dataloader-batch

sibelius avatar Jul 24 '17 09:07 sibelius