nestjs-dataloader icon indicating copy to clipboard operation
nestjs-dataloader copied to clipboard

extra params for dataloader function

Open volbrene opened this issue 4 years ago • 4 comments

Hello, is it possible to append in the loadMany and load method a "optional" parameter? I need this for add a language code to the dataloader function, because there I need it.

Or what i the best way to do this?

Thanks

volbrene

volbrene avatar Jan 24 '20 17:01 volbrene

I don't believe that would fit with the design of dataloader. The intention is that you already have an ID that ties to a specific value in some data store. Without knowing your data model, it's hard to suggest how to go about a solution. If you are just looking to cache some response, a simple memory cache may be a better solution. Otherwise, maybe you can do some filtering logic once you get the response back.

On Fri, Jan 24, 2020, 11:00 AM René Volbach [email protected] wrote:

Hello, is it possible to append in the loadMany and load method a "optional" parameter? I need this for add a language code to the dataloader function, because there I need it.

Or what i the best way to do this?

Thanks

volbrene

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/krislefeber/nestjs-dataloader/issues/10?email_source=notifications&email_token=ABTWSLF2MUI57MMWOAM6ZE3Q7MNENA5CNFSM4KLJFT62YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IISKY5A, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTWSLD4VTFCZC2XVS5QZA3Q7MNENANCNFSM4KLJFT6Q .

krislefeber avatar Jan 24 '20 19:01 krislefeber

or you can pass your region as part of the key to the DataLoader and implement a custom cacheKeyFn.

vijaych1209 avatar Sep 10 '20 15:09 vijaych1209

I am also interested in this, my use case is that I'm trying to prevent overfetching fields from my db, and in regular resolvers I can extract the needed fields from the request.

I can achieve this with regular resolvers but since the db call is in the dataloader I need to find a way to pass those required fields.

Any advice? I might just fork if I have no other choice

guy-baron1 avatar Feb 18 '21 20:02 guy-baron1

I resolved this by using an object for data loader key like {'id': 1, 'param1': 'val1', 'param2': 'val2'} instead of just id's. When you do this make sure you overwrite your "cacheKeyFn"

/**

  • Default key => key. Produces cache key for a given load key. Useful
  • when objects are keys and two objects should be considered equivalent. */ cacheKeyFn?: (key: K) => C,

Good luck.

On Thu, Feb 18, 2021 at 3:39 PM guy-baron1 [email protected] wrote:

I am also interested in this, my use case is that I'm trying to prevent overfetching fields from my db, and in regular resolvers I can extract the needed fields from the request.

I can achieve this with regular resolvers but since the db call is in the dataloader I need to find a way to pass those required fields.

Any advice? I might just fork if I have no other choice

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/krislefeber/nestjs-dataloader/issues/10#issuecomment-781620453, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWUCQOSHOKCMY7XKKNQRQLS7V3IDANCNFSM4KLJFT6Q .

vijaych1209 avatar Feb 18 '21 21:02 vijaych1209