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 and Sorting Support #103

Closed
4 tasks done
rstoyanchev opened this issue Jul 29, 2021 · 15 comments
Closed
4 tasks done

Pagination and Sorting Support #103

rstoyanchev opened this issue Jul 29, 2021 · 15 comments
Assignees
Labels
in: data Issues related to working with data type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jul 29, 2021

Investigate ways to support Pagination, for example connecting to pagination support in Spring Data repositories. There is also a specification as well. There are a different ways to control navigation, typically offset or cursor based. Spring Data currently supports offset based pagination.

Pagination depends on a predictable sort order. There doesn't seem to be any spec or ongoing effort to converge on a common approach. There is a talk on the topic that provides a good overview.

@rstoyanchev rstoyanchev added type: enhancement A general enhancement in: data Issues related to working with data labels Jul 29, 2021
@rstoyanchev rstoyanchev added this to the 1.0.0-M3 milestone Jul 29, 2021
@Diluka
Copy link

Diluka commented Aug 26, 2021

this is an example https://doug-martin.github.io/nestjs-query/docs/graphql/paging

cursor based and offset based paginations are compatible. just add offset to args and totalCount to result in cursor based pagination

@rstoyanchev rstoyanchev modified the milestones: 1.0.0-M3, 1.0 Backlog Oct 7, 2021
@SeriousSamV
Copy link

I'm trying to implement this, but just wanted to check before. When is this feature going to come out if ever?

@bclozel
Copy link
Member

bclozel commented Dec 15, 2021

@SeriousSamV I don't think this is an easy issue to tackle and we probably need to spend some time designing and iterating on that problem. This issue is not scheduled yet so we don't have a concrete plan for it. Voting for this issue and sharing useful information about use cases (see previous comments) is a way to help us make progress on this.

@yangchoo
Copy link

yangchoo commented Mar 28, 2022

Thanks again for the fantastic work on this project, it has greatly simplified the integration of graphql-java into an existing SpringBoot project.

I don't see much movement on this issue and it doesn't look like it'll be tackled as part of RC1 so I figured I'll give it a push. Pagination support is a pretty common requirement for APIs.

In terms of use-cases, we are in the process of transitioning some GET endpoints from REST to GraphQL. Previously, these endpoints return a org.springframework.data.domain.Page object, while consuming a Pageable query parameter. This is a relatively common approach for implementing paging support.

As part of the initial transition, we are utilizing an offset-based approach supported by our client. This was straightforward to implement by exposing offset/limit query arguments and creating a Pageable object from these arguments. This object can then be directly passed into a Repository.findAll method.

Ideally though, a cursor-based implementation such the relay cursor connections specification should be chosen. Besides relay, there seems to be a shift towards clients supporting that specification as a standard (e.g. see apollo).

If the full relay connections specification looks too daunting, perhaps simpler offset/cursor-based pagination implementations can be first supported? It'll be nice to rely on an official implementation vs. hand-rolling our own.

Hopefully some of this context helps. Happy to provide more if its useful. Thanks!

@saintcoder
Copy link

Is there any "temporary" of implementing pagination while this issue is addressed?

@agtraveso
Copy link

Hi! Is there any update of this issue?

We were using https://github.com/graphql-java-kickstart/graphql-spring-boot in some of our projects. It already provides pagination using relay classes -> https://www.graphql-java-kickstart.com/tools/relay. These relay classes are already defined in com.graphql-java library, so would be available in this project too. It's not necessary to reinvent the wheel :)

Probably the first step to support relay/pagination is to recognize relay directives in the schema.graphqls dinamically, generating the necessary classes.

@Michal-Kucera
Copy link

Hello, I'd like to share my workaround for Pagination and Sorting Support for Spring GraphQL, using Kotlin, although it doesn't work with cursors (as per spring-projects/spring-data-commons#2151).

https://gist.github.com/Michal-Kucera/a0ad1572a0c212dc8b67b8136c7cb78c

P.S. I didn't try it out with nested schemas..

Once Spring data common supports cursors, we may reuse classes from graphql-java, relay package, i.e.:

  • graphql.relay.Connection
  • graphql.relay.Edge
  • graphql.relay.PageInfo
  • graphql.relay.ConnectionCursor

There is also an interesting class graphql.relay.Relay, which might be worth investigating further.

Cheers!
Michal

@rstoyanchev rstoyanchev self-assigned this Dec 9, 2022
@rstoyanchev rstoyanchev modified the milestones: 1.2 Backlog, 1.2.0-M1 Dec 9, 2022
@cezary-butler
Copy link

Hi. I am also interested in the pagination support. Especially in the QuerydslDataFetcher context.
For adding ability to customize QuerydslDataFetcher would be sufficient. right now I don't see a way to add any code that would run at the end of ManyEntityFetcher.get method, without reimplementing big part of QuerydslDataFetcher and unexposed classes it uses.

@rstoyanchev
Copy link
Contributor Author

Thanks for the comment, @cezary-butler. I've created #597 as a more specific issue for now. Let's continue the discussion there.

@rstoyanchev
Copy link
Contributor Author

I've turned this into an umbrella issue. See issue description at the top for a list of sub-tasks for the actual work.

@rstoyanchev rstoyanchev modified the milestones: 1.2.0-M1, 1.2.0-RC1 Mar 21, 2023
@roksui
Copy link

roksui commented Mar 29, 2023

Is pagination support only possible with spring boot v3.x.x and not v2.7.x? I am currently using v2.7.8 and I wonder if there is any way to implement pagination using spring-for-graphql?

@bclozel
Copy link
Member

bclozel commented Mar 29, 2023

@chop-sui this new feature will be available as of Spring for GraphQL 1.2.0 (so Spring Boot 3.1.0). We don't backport new features.

@rstoyanchev
Copy link
Contributor Author

rstoyanchev commented Mar 29, 2023

It also depends on what exactly you need from pagination. If using Spring Data pagination, then yes we'll have 1st class support for that in 1.2 (only), but that in turn depends on Spring Data's cursor support that's also in development. You can also adapt other persistence pagination mechanisms, but obviously that can't be built in, and you'll need to upgrade to make use of that.

If it's just Connection schema type generation, then it's straight forward, see ConnectionTypeDefinitionConfigurer for example.

@roksui
Copy link

roksui commented Mar 31, 2023

@bclozel @rstoyanchev Thank you for comfirming. I am planning to use Spring Data pagination with connection style GraphQL pagination. I will look into migrating to Spring Boot 3 as the project I'm working on has started only recently.

@rstoyanchev
Copy link
Contributor Author

I'm closing this umbrella issue since all sub-tasks are now complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues related to working with data type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

10 participants