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

Does not work with class-validator 0.14.0 #1443

Closed
Martomate opened this issue Apr 6, 2023 · 5 comments
Closed

Does not work with class-validator 0.14.0 #1443

Martomate opened this issue Apr 6, 2023 · 5 comments
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists

Comments

@Martomate
Copy link

Describe the Bug
When TypeGraphQL 1.1.1 is used together with class-validator 0.14.0 the TypqGraphQL validation stops working (it crashes).

This happens in the validate-args file and the reason is most likely that there was a breaking change in class-validator 0.14.0 (see here). All my integration tests work with class-validator 0.13.2, but most of them fail with 0.14.0.

To Reproduce

Create a resolver with a mutation that takes this input:

@InputType()
export class SaveCredentialsInput {
  @Field()
  username!: string

  @Field()
  password!: string
}

This is what is returned to the API caller:

{
  "message": "Argument Validation Error",
  "locations": [
    {
      "line": 3,
      "column": 9
    }
  ],
  "path": ["saveCredentials"],
  "extensions": {
    "code": "INTERNAL_SERVER_ERROR",
    "exception": {
      "validationErrors": [
        {
          "target": {
            "username": "test",
            "password": "test"
          },
          "children": [],
          "constraints": {
            "unknownValue": "an unknown value was passed to the validate function"
          }
        }
      ],
      "stacktrace": [
        "Error: Argument Validation Error",
        "    at Object.validateArg (/app/node_modules/type-graphql/dist/resolvers/validate-arg.js:29:15)",
        "    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
        "    at async Promise.all (index 1)"
      ]
    }
  }
}

For some reason TypeGraphQL uses class-validator without specifying it as a dependency, so I was quite surprised to find this incompatibility.

@carlocorradini
Copy link
Contributor

carlocorradini commented Apr 6, 2023

See #1397

Using class-validator >=0.14.0:

const schema = await buildSchema({
  // ...
  validate: { forbidUnknownValues: false } // <--
});

@MichalLytek
Copy link
Owner

Closing as duplicate #1396 #1401 🔒

@MichalLytek MichalLytek added Duplicate 🔑 This issue or pull request already exists Community 👨‍👧 Something initiated by a community labels Apr 7, 2023
@mmmeff
Copy link

mmmeff commented Jul 27, 2023

Is there still a security risk here with class-validator? According to its maintainers, the main change in 0.14.0 was to enable forbidUnknownValues by default

@MichalLytek
Copy link
Owner

With GraphQL I guess not, it has own type system, fields validation and you can't put values not present in schema.

@aikr-trifork
Copy link

aikr-trifork commented Oct 24, 2024

See #1397

Using class-validator >=0.14.0:

const schema = await buildSchema({
  // ...
  validate: { forbidUnknownValues: false } // <--
});

Thanks, this worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants