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
You'd just want to write some helper functions and then implement them in your resolver file
That would be a good use-case for pipes integration.
@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()?
@partyka95 we don't need that, see microservices & websockets. you can use pipes with them already
Could anyone give an example?
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!
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.
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?
I'm interested in this as well. Maybe with anotations on the fields in the
schema?
On Fri, Nov 9, 2018, 06:32 Zeldaze notifications@github.com wrote:
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?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nestjs/graphql/issues/3#issuecomment-437255096, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AE64MKW58oNuR1213DNmIS5pI1VLes98ks5utRN7gaJpZM4RVVxf
.
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.