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

Enforce pagination on generated resolvers #446

Open
shawnjones253 opened this issue Mar 29, 2024 · 3 comments
Open

Enforce pagination on generated resolvers #446

shawnjones253 opened this issue Mar 29, 2024 · 3 comments
Labels
community Something initiated by the community enhancement New feature or request

Comments

@shawnjones253
Copy link

Is your feature request related to a problem? Please describe.
It is not possible to enforce pagination using auto-generated resolvers. This makes it easy for API requests to ask for more data than can fit into memory, crashing the API.

Describe the solution you'd like
For context, we're using the generated relational resolvers currently, but are hoping to implement graphql amount limiting / pagination across the API. Something similar to this.

In resolvers we've written ourselves, I'd simply replace the type of take in any FindManyXYZArgs with a custom scalar that enforces minimum and maximum values, additionally making it required rather than nullable.

Unfortunately this isn't possible with generated resolvers.

I'd imagine an ideal solution would allow me to do something like:

Would you consider a PR to add this to the generator?

generator typegraphql {
  provider            = "typegraphql-prisma"
  findManyTakeType = "./path/to/myCustomScalar.ts"
}

Describe alternatives you've considered
As an alternative, I've considered doing a one-time generation of the relational resolvers to my repository, then discontinuing use of the generated relational resolvers going forward. This creates a fairly large (new) burden on developers for future work however.

@MichalLytek
Copy link
Owner

I would rather see defaultTake = 20 or maxTake = 100 config that would generate proper statement in generated resolver to set value for take/limit.

For overwriting scalars we have a different ticket and a different approach.

@MichalLytek MichalLytek added enhancement New feature or request community Something initiated by the community labels Mar 30, 2024
@electrovir
Copy link

electrovir commented Apr 23, 2024

@MichalLytek is there currently a way to add those defaultTake or maxTake configs you mentioned? Or were you saying that that's what this requested feature needs to add?

@shawnjones253
Copy link
Author

He’s saying that’s what I’d need to add if submitting a PR. I do plan to make such a PR in the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Something initiated by the community enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants