Skip to content

BREAKING CHANGE: Fix graphql errors #12775

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

Merged
merged 10 commits into from
Jun 23, 2025
Merged

BREAKING CHANGE: Fix graphql errors #12775

merged 10 commits into from
Jun 23, 2025

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Jun 21, 2025

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Major overhaul of validation architecture across the server, moving from global validation to resolver-specific validation with new pipe implementations.

  • Significant security concern: CaptchaService now bypasses all CAPTCHA validation by always returning success, potentially exposing the system to automated attacks
  • Introduced ResolverValidationPipe for GraphQL and HttpControllerValidationPipe for REST endpoints, implementing proper validation using class-validator
  • Removed global validation pipe from main.ts in favor of module-specific validation pipes in GraphQL resolvers
  • Added consistent validation across key resolvers including FieldMetadataResolver and AuthResolver

8 files reviewed, 4 comments
Edit PR Review Bot Settings | Greptile

@@ -10,12 +10,8 @@ export class CaptchaService implements CaptchaDriver {
constructor(@Inject(CAPTCHA_DRIVER) private driver: CaptchaDriver) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Driver is injected but never used. Either remove the injection or use the driver for validation.

Comment on lines 38 to 39
private toValidate(metatype: any): boolean {
const types = [String, Boolean, Number, Array, Object];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Replace 'any' type with 'Function | undefined' for better type safety

Suggested change
private toValidate(metatype: any): boolean {
const types = [String, Boolean, Number, Array, Object];
private toValidate(metatype: Function | undefined): boolean {
const types = [String, Boolean, Number, Array, Object];

Comment on lines 31 to 33
private toValidate(metatype: unknown): boolean {
const types: unknown[] = [String, Boolean, Number, Array, Object];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The types array is typed as unknown[] but contains concrete types. This could cause type safety issues. Use const types: Function[] instead for proper type checking.

Suggested change
private toValidate(metatype: unknown): boolean {
const types: unknown[] = [String, Boolean, Number, Array, Object];
private toValidate(metatype: unknown): boolean {
const types: Function[] = [String, Boolean, Number, Array, Object];

Comment on lines +37 to +44
private formatErrorMessage(errors: ValidationError[]): string {
const messages = errors.flatMap((error) => {
if (error.constraints) {
return Object.values(error.constraints);
}

return [];
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider handling nested validation errors by recursively processing error.children. Currently nested object validation errors might not be properly formatted.

Copy link
Contributor

github-actions bot commented Jun 21, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:56702

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Contributor

github-actions bot commented Jun 21, 2025

📊 API Changes Report

GraphQL Schema Changes

GraphQL Schema Changes

[log]
Detected the following changes (2) between schemas:

[log] ✖ Type ClientConfig was removed
[log] ✖ Field clientConfig was removed from object type Query
[error] Detected 2 breaking changes
⚠️ Breaking changes or errors detected in GraphQL schema

[log] 
Detected the following changes (2) between schemas:

[log] ✖  Type ClientConfig was removed
[log] ✖  Field clientConfig was removed from object type Query
[error] Detected 2 breaking changes
Error generating diff

GraphQL Metadata Schema Changes

GraphQL Metadata Schema Changes

[log]
Detected the following changes (2) between schemas:

[log] ✖ Type ClientConfig was removed
[log] ✖ Field clientConfig was removed from object type Query
[error] Detected 2 breaking changes
⚠️ Breaking changes or errors detected in GraphQL metadata schema

[log] 
Detected the following changes (2) between schemas:

[log] ✖  Type ClientConfig was removed
[log] ✖  Field clientConfig was removed from object type Query
[error] Detected 2 breaking changes
Error generating diff

⚠️ Please review these API changes carefully before merging.

✅ Breaking Change Protocol

This PR title contains "breaking" and breaking changes were detected - the CI will fail as expected.

📝 Action Required: Please add BREAKING CHANGE: to your commit message to trigger a major version bump.

Example:

feat: add new API endpoint

BREAKING CHANGE: removed deprecated field from User schema

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, agree with the custom decorator

@charlesBochet charlesBochet changed the title Fix graphql errors BREAKING CHANGE: Fix graphql errors Jun 23, 2025
@charlesBochet charlesBochet merged commit b76dac2 into main Jun 23, 2025
57 of 59 checks passed
@charlesBochet charlesBochet deleted the fix-graphql-errors branch June 23, 2025 09:23
Copy link

sentry-io bot commented Jun 27, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants