Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise never triggered #36

Open
videni opened this issue May 21, 2020 · 1 comment
Open

Promise never triggered #36

videni opened this issue May 21, 2020 · 1 comment

Comments

@videni
Copy link

videni commented May 21, 2020

I use the example here, but the promise returned by loadMany method never get triggered, why?

class CustomerLoader {

   /**
     * @var WebonyxGraphQLSyncPromiseAdapter
     */
    private $promiseAdapter;

    public function __construct($promiseAdapter)
    {
        $this->promiseAdapter = $promiseAdapter
    }

 public function all(array $userIds)
    {
        $users = CSessionInfo::query()
            ->whereIn('id', $userIds)
            ->get()
            ->groupBy('id');

        $indexed = array_reduce($userIds, function($curry, $current) use($users) {
             $curry[] = $users->has($current) ? $users->get($current): null;
             return $curry;
        }, []);

        return $this->promiseAdapter->all($indexed);
    }

  public function getLoader()
    {
        return new DataLoader(function(array $userIds){
            $this->all($userIds);
        }, $this->promiseAdapter);
    }

   // this method is mapped to author field .
    public function resolveAuthor($parent)
    {
        return $this->getLoader()->load($parent['authorId']);
    }
}

$graphQLPromiseAdapter = new SyncPromiseAdapter();
$dataLoaderPromiseAdapter = new WebonyxGraphQLSyncPromiseAdapter($graphQLPromiseAdapter);
$userLoader = new DataLoader(function ($keys) { /.../ }, $dataLoaderPromiseAdapter);

GraphQL::setPromiseAdapter($graphQLPromiseAdapter);

@simPod
Copy link
Contributor

simPod commented Nov 22, 2021

@videni is it fixed or can you provide a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants