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

Validation fails if query arg is a list with null items #1328

Closed
papermana opened this issue Aug 12, 2022 · 0 comments · Fixed by #1329
Closed

Validation fails if query arg is a list with null items #1328

papermana opened this issue Aug 12, 2022 · 0 comments · Fixed by #1329
Assignees
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community
Projects
Milestone

Comments

@papermana
Copy link
Contributor

papermana commented Aug 12, 2022

Describe the Bug
If validation is on, and I make a query where one of the arguments is a list containing at least one null, then the query will fail with a message "validationErrors: TypeError: Cannot read properties of null (reading 'constructor')".

To Reproduce
Have a query like:

myQuery(@Arg('inputs', () => [Foo], { nullable: 'items' }) inputs: Array<Foo | null>) {
  // ...
}

Then, perform a query like

query Foo {
 myQuery(inputs: [null])
}

Expected Behavior
There should be no validation error.

Logs

ArgumentValidationError: Argument Validation Error
    at Object.validateArg (/Users/dominik/projects/snipped/node_modules/type-graphql/dist/resolvers/validate-arg.js:29:15)
    at async Promise.all (index 1)
    at async Promise.all (index 0) {
  validationErrors: TypeError: Cannot read properties of null (reading 'constructor')
      at ValidationExecutor.execute (/Users/dominik/projects/snipped/node_modules/src/validation/ValidationExecutor.ts:57:14)
      at Validator.coreValidate (/Users/dominik/projects/snipped/node_modules/src/validation/Validator.ts:107:14)
      at Validator.validateOrReject (/Users/dominik/projects/snipped/node_modules/src/validation/Validator.ts:53:31)
      at validateOrReject (/Users/dominik/projects/snipped/node_modules/src/index.ts:91:40)
      at /Users/dominik/projects/snipped/node_modules/type-graphql/dist/resolvers/validate-arg.js:21:55
      at Array.map (<anonymous>)
      at Object.validateArg (/Users/dominik/projects/snipped/node_modules/type-graphql/dist/resolvers/validate-arg.js:21:40)
      at async Promise.all (index 1)
      at async Promise.all (index 0)
}

Environment (please complete the following information):

  • OS: macOS 12.2.1
  • Node 16.14.0
  • Package version 1.0.0-rc.1, but tested 1.1.1 as well
  • TypeScript version 4.5.4

Additional Context
n/a

@MichalLytek MichalLytek added Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community labels Aug 16, 2022
@MichalLytek MichalLytek added this to Backlog in Board via automation Aug 17, 2022
@MichalLytek MichalLytek added this to the 1.2 release milestone Aug 17, 2022
@MichalLytek MichalLytek moved this from Backlog to In review in Board Aug 17, 2022
@MichalLytek MichalLytek moved this from In review to Done in Board Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community
Projects
Board
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants