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

Schema validation #3

Closed
pawpartyka opened this issue Jan 6, 2018 · 10 comments
Closed

Schema validation #3

pawpartyka opened this issue Jan 6, 2018 · 10 comments
Assignees

Comments

@pawpartyka
Copy link
Contributor

pawpartyka commented Jan 6, 2018

Hello,

Is there any good way to validate data in mutations like string length etc?

typescript mutation { createSth(name:"something", website:"http://test.com/") { id name website } }

How can i validate name or website data?

PS: Kamil, great job with nestjs!

Regards

@pawpartyka pawpartyka changed the title Decorators for resolvers (validation) Schema validation Jan 6, 2018
@iamclaytonray
Copy link

You'd just want to write some helper functions and then implement them in your resolver file

@kamilmysliwiec
Copy link
Member

That would be a good use-case for pipes integration.

@pawpartyka
Copy link
Contributor Author

@kamilmysliwiec To use the pipes, we need a decorators like @Body(new ValidatorPipe()) in controllers, right? Do you have plans to create a decorator for resolvers like @Args()?

@kamilmysliwiec
Copy link
Member

@partyka95 we don't need that, see microservices & websockets. you can use pipes with them already

@pawpartyka
Copy link
Contributor Author

Could anyone give an example?

@VinceOPS
Copy link

VinceOPS commented Feb 24, 2018

At the present time, it looks like pipes are loaded by the PipesContextCreator, which is used by the "context creator" of RPC (microservices), WS (websocket) and Routes.
But Resolver (from nestjs/graphql) uses ExternalContextCreator (from nestjs/nest), which, at the present time, only uses the GuardsContextCreator and InterceptorsContextCreator.
It looks like the Pipes are set up between the Guards and the Interceptors and should be inserted around here in ExternalContextCreator.

@kamilmysliwiec is it correct? Would it take a lot of work to me to create a PR? Or should we do something special for GraphQL Resolvers? (Like targetting body in the rootValue (which is most likely req, if everyone's following the documentation)?)

Thanks!

@kamilmysliwiec
Copy link
Member

ExternalContextCreator has to be agnostic, meaning, we cannot adjust it to the GraphQL purposes. As a result, pipes won't be integrated with @nestjs/graphql package. Instead, you can keep validation responsibilities in the business logic.

@Zeldaze
Copy link

Zeldaze commented Nov 9, 2018

Any clearer examples on how to best implement validation for mutation inputs? Things like min/max lengths, advanced type fields etc. that we are used to from packages like class-validator?

@biels
Copy link

biels commented Nov 9, 2018 via email

@lock
Copy link

lock bot commented Apr 25, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants