BREAKING CHANGE: Fix graphql errors (#12775)
We were using a global ValidationPipe in main.ts. This is an issue as @Controllers should return HttpExecption and @Resolvers should return GraphqlErrors Removing the global pipe and creating a ResolverValidationPipe able to generate GraphqlError. We also need to handle the exception in a filter to avoid nest to think it's unhandled and make it flow to logs Next step: - it would be nice to have both @UsePipes(ResolverValidationPipe) + @UseFilters(GraphqlValidationExceptionFilter) come together. This should be possible if we create a @GraphQLResolver annotation
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import bytes from 'bytes';
|
||||
import { useContainer, ValidationError } from 'class-validator';
|
||||
import { useContainer } from 'class-validator';
|
||||
import session from 'express-session';
|
||||
import { graphqlUploadExpress } from 'graphql-upload';
|
||||
|
||||
@ -50,22 +49,6 @@ const bootstrap = async () => {
|
||||
|
||||
app.useGlobalFilters(new UnhandledExceptionFilter());
|
||||
|
||||
// Apply validation pipes globally
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
exceptionFactory: (errors) => {
|
||||
const error = new ValidationError();
|
||||
|
||||
error.constraints = Object.assign(
|
||||
{},
|
||||
...errors.map((error) => error.constraints),
|
||||
);
|
||||
|
||||
return error;
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.useBodyParser('json', { limit: settings.storage.maxFileSize });
|
||||
app.useBodyParser('urlencoded', {
|
||||
limit: settings.storage.maxFileSize,
|
||||
|
||||
Reference in New Issue
Block a user