GraphQL Dataloader on non-id fields?

GraphQL Dataloader on non-id fields?


0

We’re using NodeJS (typescript) and GraphQL for our backend.
Therefore we rely heavily on dataloaders, and we get more and more field resolvers that needs to be resolved on something other than IDs.

An example is a field resolver on our User object, called "follows_me". In this case we need to make a lookup in our Follower collection, and match on the two user ids. Is this even possible to solve using dataloaders? To my understanding, dataloaders rely on only having one field to match on?

Here’s some example code for context:

@FieldResolver(returns => Follower, { nullable: true })
async follows_me(
    @Root() user: DocumentType<User>,
    @Ctx() context: AppContext
) {
    // TODO: Use dataloader???
    return Followers.findOne({
        user_id: user._id,
        follow_user_id: context.user._id,
    });
}


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *