Skip to content

Share dataloader between loadable objectFields #1307

Answered by hayes
alexandernanberg asked this question in Q&A
Discussion options

You must be logged in to vote

Creating your own data-loader for this is the right way to go. I've looked into trying to support this in the data-loader plugin, but couldn't find an API that seemed better than just creating the dataloader directly.

One thing that might be useful is the createContextCache method, that lets you get a dataloader without having to add it to the context object directly. Not really different than what you are already doing, but I like it for encapsulation

const getMemberLoader = createContextCache(() => new DataLoader((ids: readonly string[]) => {
 // Implement dataloader here
}))

builder.objectField(User, 'memberships', (t) =>
  t.loadable({
    type: UserOrgMembersConnection,
    byPath: t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alexandernanberg
Comment options

Answer selected by alexandernanberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants