Closed nicky-lenaers closed 5 years ago
That seems more like a module/side/lib than core.
I hope you don't go that way, it will make the framework team bugs double at least, not to mention the difficulty to deploy new framework versions.
My 2cents.
@malkaviano Thank you for your comment. There's a couple of things I'd like to address.
That seems more like a module/side/lib than core.
You're absolutely right about this. It should be a module, for the same reason @nestjs/mongoose
and @nestjs/graphql
are modules: it's an opt-in. When configured as a module, it would play nicely between a TypeORM / Mongoose and GraphQL.
I hope you don't go that way, it will make the framework team bugs double at least, not to mention the difficulty to deploy new framework versions.
I think it is a major stretch to assume a doubling of framework team bugs here. Just because it is a non-trivial feature doesn't mean it will produce bugs. It should be discussed and designed up front in order to have an integration plan for the module so to prevent design flaws, not to mention a CI/CD pipeline as a guard for production environments. There is already a detailed guideline for Relay Cursor Pagination by Facebook available that can be used to refine and adjust the design. In short, I do not agree with this remark.
I hope this feature could still be considered and discussed, as many web applications nowadays need some form of pagination / infinite loading features for performance reasons.
@nicky-lenaers Yeah about the second part of my post, I did it before learning more about Nestjs, looks like you already went that way so it's unfair to block this feature exactly.
It's a good feature indeed.
Just for clarification, I did not mean the feature couldn't be part of Nestjs or developed by the same team, I just meant it shouldn't be in the core package. Maybe that point needed more clarification.
@malkaviano Thanks for your clarification :)
Works great, unless I try to use RecipesPage in another module's model. Then I get, Cannot read property 'name' of undefined
for Paginated${TClass.name}Edge
.
Any ideas?
@WillSquire So that means that TClass
is undefined. So it could be an error in:
@ObjectType()
export class RecipesPage extends Page(Recipes) {}
Are you sure you imported the Page
function?
@nicky-lenaers Yes, I'm sure. It works in some places, but using it another module's model brings up the error. Banged my head for quite a while before removing it.
@nicky-lenaers Yes, I'm sure. It works in some places, but using it another module's model brings up the error. Banged my head for quite a while before removing it.
Probably a circular dependency issue.
@marcus-sa Yeah, I thought the same thing but it's a type rather than an instance so I wasn't sure if it was resolvable in the same way as the nest docs mention?
We don't plan to release this feature as part of the ecosystem packages (no bandwidth to handle that). However, if anyone would ever release such a package, please, let others know here!
@kamilmysliwiec Thanks for clarifying! Keep up great work at Nest 👍
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Feature Request
Nest is one of the most robust NodeJS frameworks out there. However, I think it would be nice to incorporate some form of out-of-the-box pagination using GraphQL and Mongoose (or any TypeORM for that matter). In this feature request I'd like to present my 2 cents for the idea of a pagination feature in Nest. I found myself using pagination in the context of GraphQL and Mongoose very often and I think others might be so too. Hence I think Nest could adopt the concept of pagination into its framework.
Is your feature request related to a problem? Please describe.
It is not.
Describe the solution you'd like
I while back I started the creation of a package I call MoGr, which combines Mongoose and GraphQL to allow for automated query projection, population and pagination.
You can check out the MoGr package on GitHub here.
In order to allow for pagination, I've set up the following steps using the MoGr package:
1. Pagination Service
First, a MoGr registry is created to store information coming from Mongoose and GraphQL. It uses the
InjectConnection
param decorator to retrieve the MongoDB connection.pagination.service.ts
2. Pagination Module
A module is created to hold and export the
PaginationService
:pagination.module.ts
3. Models for Edge, PageInfo and Page
Based on cursor-based pagination guidelines, the models for
Edge
,PageInfo
andPage
are as follows:edge.interface.ts
page-info.interface.ts
page.interface.ts
4. GraphQL Object Types for Edge, PageInfo and Page
Using the defined models for
Edge
,PageInfo
andPage
, we can now construct GraphQL Object Types. Notice thatPage
uses the generic type functionality fromtype-graphql
:page-info.type.ts
page.type.ts
5. GraphQL Input Types for Filters and Query Options
Now we need a GraphQL Input Type in order to supply pagination filters and query options:
enums.ts
order-by.interface.ts
query-options.interface.ts
query-options.type.ts
filter-string.input.ts
filter-string-contains.input.ts
6. Usage - Arguments
To utilize the above types, we take the example of
Recipes
:enums.ts
recipes.args.ts
page-field-filter.interface.ts
recipes-filters.input.ts
6. Usage - Page
To utilize the above types, we keep using the example of
Recipes
:recipies-page.type.ts
Then, on the
RecipesResolver
, we can use the pagination as follows:recipes.resolver.ts
The
RecipesService
looks as follows (using the MoGr package):Now, any type can be paginated using the generic
Page
type and the generic filters and query options.Teachability, Documentation, Adoption, Migration Strategy
This would need some documentation afterwards. This issue is just for proposing the idea of pagination.
What is the motivation / use case for changing the behavior?
Pagination is needed in many mondern web application for e.g. infinite scrolling, huge data-tables and much more. It would be a nice addition to the Nest package.