Skip to content

[BUG] batchScheduleFn is always called even if value taken from cache #243

@sonnenhaft

Description

@sonnenhaft

Expected Behavior

"batchScheduleFn" should not get called when value is taken from cache

Current Behavior

"batchScheduleFn" is called always and delaying response

Possible Solution

after checking if value is in cache - to ignore "batchScheduleFn"

Steps to Reproduce

Console log in "batchScheduleFn", it is called always

Activity

CreatCodeBuild

CreatCodeBuild commented on Jun 17, 2020

@CreatCodeBuild

why is this behavior a bug?

twavv

twavv commented on Sep 6, 2020

@twavv

This isn't (from my perspective) a bug. It helps synchronize execution.

Suppose you have a function

function getFriends(userId) {
  const user = userLoader.load(userId);
  const friends = userLoader.loadMany(user.friendIds);
  return friends;
}

Suppose foo is already in the DataLoader cache, and we call

const fooFriends = getFriends("foo");
const barFriends = getFriends("bar");
console.log(Promise.all([fooFriends, barFriends]));

We actually WANT the call to userLoader.load("foo") to be scheduled with the next batch, so that the two .loadMany calls are synchronized.

CreatCodeBuild

CreatCodeBuild commented on Sep 13, 2020

@CreatCodeBuild

@travigd exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @twavv@sonnenhaft@CreatCodeBuild

        Issue actions

          [BUG] batchScheduleFn is always called even if value taken from cache · Issue #243 · graphql/dataloader