We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
main.ts
create-user.input.ts
Test input: { "input": { "username": "a", "password": "12345678", } }
{ "input": { "username": "a", "password": "12345678", } }
Result with plain ValidationPipe:
Result with I18nValidationPipe:
The issue is reproducible with: "@nestjs/apollo": "^12.0.11" "@nestjs/graphql": "^12.0.11"
With old packages everything works as expected: "@nestjs/apollo": "^10.2.0", "@nestjs/graphql": "^10.2.0"
Use any class-validator annotation on field and try to make a mutation.
System: OS: Linux 6.2 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish) CPU: (16) x64 AMD Ryzen 7 7700X 8-Core Processor Memory: 20.91 GB / 30.49 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm Browsers: Chrome: 120.0.6099.71
yarn
The text was updated successfully, but these errors were encountered:
This can be resolved by changing the link as below.
exception.extensions = { errors: normalizedErrors };
But I need something custom, so I use it like below: i18n-gql-validation-exception.filter.ts
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common'; import { GqlContextType } from '@nestjs/graphql'; import { I18nContext, I18nValidationException } from 'nestjs-i18n'; import { formatI18nErrors } from 'nestjs-i18n/dist/utils'; @Catch(I18nValidationException) export class I18nGqlValidationExceptionFilter implements ExceptionFilter { catch(exception: any, host: ArgumentsHost) { if (host.getType<GqlContextType>() !== 'graphql') { return exception; } const i18n = I18nContext.current<I18nTranslations>(host); if (!i18n) { return exception; } const errors = formatI18nErrors(exception.errors, i18n.service, { lang: i18n.lang }); const constraints = errors?.[0].constraints; if (constraints && Object.values(constraints).length > 0) { exception.message = Object.values(constraints)[0]; exception.extensions = { errors }; } return exception; } }
app.useGlobalPipes(new I18nValidationPipe({ transform: true })); app.useGlobalFilters(new I18nGqlValidationExceptionFilter());
Sorry, something went wrong.
No branches or pull requests
Describe the bug
main.ts
create-user.input.ts
Test input:
{ "input": { "username": "a", "password": "12345678", } }
Result with plain ValidationPipe:
Result with I18nValidationPipe:
The issue is reproducible with:
"@nestjs/apollo": "^12.0.11"
"@nestjs/graphql": "^12.0.11"
With old packages everything works as expected:
"@nestjs/apollo": "^10.2.0",
"@nestjs/graphql": "^10.2.0"
Reproduction
Use any class-validator annotation on field and try to make a mutation.
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: