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

[Laravel] GraphQL Cursor Pagination not working #6747

Open
toitzi opened this issue Oct 24, 2024 · 2 comments
Open

[Laravel] GraphQL Cursor Pagination not working #6747

toitzi opened this issue Oct 24, 2024 · 2 comments

Comments

@toitzi
Copy link
Contributor

toitzi commented Oct 24, 2024

API Platform version(s) affected: 4.0.4
Cursor Pagination with $after, etc... using graphql seems to not work in Laravel.
I think there are 2 Issues with it:

  1. It is not really a cursor based pagination (see this issue)
  2. It does not seem to be accounted at all (at least not in the laravel implementation) - this might be due to how laravel simplePaginate works (assuming that cursor based pagination is considered "partial" pagination, which it isn't automatically) and that there is no offset option for that.

A potential fix could be using laravels cursorPaginate function, but some serialization and deserialization of the cursor would need to be also added for this to work. Also GraphQL operations making use of that, should automatically be considered partial paginations.

I will try to open a PR for this.

@toitzi
Copy link
Contributor Author

toitzi commented Nov 11, 2024

@soyuka I now have time to implement this laravel...but laravel only supports the following for cursor pagination:

Number of Items (first)
Current Cursor (after)

Current options like: befre, first, last would not be available.

Or at least not directly. Before could be implemented by returning the cursor of the previous page however it would probably need a different name since nItems (e.g. 10) before cursor "x" would mean 10 cursor items AFTER x

I do not know about non cursor pagination and symfonys / doctrine way tbh and wouldn't therefore want to fiddle arround there. There exists this PR for it, all i would do is take the CursorPaginatorInterface from there so if that PR is merged it will work together with this.

But to archive this correctly (and in a simple manner) i would need to extend TypeBuilder and FieldsBuilder for Laravel inside the src/laravel directory (to avoid adapting the graphql package and it's contents) since getCursorBasedPaginationFields and getGraphQlPaginationArgs need to work differently and only return "first" and "after" as possible options in the schema. This can be done easily (i think lol) since we can then inject it in the ApiPlatformServiceProvider..which sort of already happens.

Is that okay to do or do you have something different in mind?

@toitzi
Copy link
Contributor Author

toitzi commented Nov 11, 2024

Ah never mind TypeBuilder and FieldsBuilder are final. Would need to change that, or the files directly, and see how it works out in the symfony/doctrine universe...so yeah you would need to decide what to do

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

No branches or pull requests

2 participants