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

Pagination helper - backward count does not work with promises #286

Open
akomm opened this issue Jan 31, 2018 · 3 comments
Open

Pagination helper - backward count does not work with promises #286

akomm opened this issue Jan 31, 2018 · 3 comments
Labels

Comments

@akomm
Copy link
Member

akomm commented Jan 31, 2018

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch dev-master

Paginator $count callback does work with promise when using forward, but not backward. In case of backward, you get:

Object of class GraphQL\\Executor\\Promise\\Promise could not be converted to int

Example code:

$paginator = new Paginator(function($offset, $limit) {
    return $this->someLoader->load(new SomeKey($criteria, $offset, $limit))->then(function(array $ids) {
        return $this->someOtherLoader->loadMany($ids);
    });
});
$paginator->auto($args, function() {
    return $this->someLoader->load(new SomeKey($criteria))->then(FnUtils::arrayLikeCount());
});
@mcg-web
Copy link
Member

mcg-web commented Jan 31, 2018

Try this please:

$paginator = new Paginator(function($offset, $limit) {
    return $this->someLoader->load(new SomeKey($criteria, $offset, $limit))->then(function(array $ids) {
        return $this->someOtherLoader->loadMany($ids);
    });
}, Paginator::MODE_PROMISE);

@akomm
Copy link
Member Author

akomm commented Jan 31, 2018

Sorry, I did it already, forgot to add it to the sample code. Otherwise it would not work with forward too.

Also note: the note is raised after the $count callback invokation, not the paginator callback. So the issue is the promise returned from $count:

$paginator->auto($args, function() {
    return $this->someLoader->load(new SomeKey($criteria))->then(FnUtils::arrayLikeCount());
});

arrayLikeCount is a x => count(x); with some checks.

@mcg-web mcg-web added the bug label Jan 31, 2018
@akomm
Copy link
Member Author

akomm commented Jan 31, 2018

I think the reason, why the notice does not trigger in case of forward is because it is not accessed there, while the backward does access the Connection::$totalCount and therefore triggers the error. So probably the issue is in general, that the $count callback in Paginator is not supporting promise itself?

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

No branches or pull requests

2 participants