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

Array or null validation error #57

Open
ziimakc opened this issue Aug 28, 2022 · 4 comments · May be fixed by #67
Open

Array or null validation error #57

ziimakc opened this issue Aug 28, 2022 · 4 comments · May be fixed by #67
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ziimakc
Copy link

ziimakc commented Aug 28, 2022

UPD. Found a workaround by setting directiveValidation: false, in my case it doesn't matter as I don't use directive mercurius validation.

For gql type CreateInput args nums and description are optional, so we can pass { nums: null, description: null } in CreateInput:

input CreateInput {
    description: String
    nums: [Int!]
}

Validation:

  CreateInput : {
    nums: {
      type: 'array',
      nullable: true,
      maxItems: 10,
      uniqueItems: true,
      items: { type: 'integer', minimum: 0, maximum: 9 },
    },
   description: { type: 'string', maxLength: 1000 }
  },

For some reason I get error when { nums: null } is passed as argument while { description: null } or { nums: [] } works:

      "message": "Failed Validation on arguments for field 'Mutation.smthCreate'",
      "stack":
          ValidationError: Failed Validation on arguments for field 'Mutation.smthCreate'
              at node_modules\.pnpm\[email protected]\node_modules\mercurius-validation\lib\validators\validator.js:32:15
              at executeField (node_modules\.pnpm\[email protected]\node_modules\graphql\execution\execute.js:481:20)
              at node_modules\.pnpm\[email protected]\node_modules\graphql\execution\execute.js:377:22
              at promiseReduce (node_modules\.pnpm\[email protected]\node_modules\graphql\jsutils\promiseReduce.js:23:9)
              at executeFieldsSerially (node_modules\.pnpm\[email protected]\node_modules\graphql\execution\execute.js:373:43)
              at executeOperation (node_modules\.pnpm\[email protected]\node_modules\graphql\execution\execute.js:347:14)
              at execute (node_modules\.pnpm\[email protected]\node_modules\graphql\execution\execute.js:136:20)
              at Object.fastifyGraphQl [as graphql] (node_modules\.pnpm\[email protected][email protected]\node_modules\mercurius\index.js:654:29)
              at _Reply.graphql (node_modules\.pnpm\[email protected][email protected]\node_modules\mercurius\index.js:340:16)
              at executeQuery (node_modules\.pnpm\[email protected][email protected]\node_modules\mercurius\lib\routes.js:224:18)
      "path": [
        "smthCreate"
      ],
      "locations": [
        {
          "line": 3,
          "column": 3
        }
      ],
      "extensions": {
        "name": "ValidationError",
        "details": [
          {
            "instancePath": "/input/nums",
            "schemaPath": "https://mercurius.dev/validation/CreateInput/properties/nums/type",
            "keyword": "type",
            "params": {
              "type": "array"
            },
            "message": "must be array",
            "schema": "array",
            "parentSchema": {
              "type": "array",
              "maxItems": 10,
              "uniqueItems": true,
              "items": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9
              },
              "$id": "https://mercurius.dev/validation/CreateInput/nums"
            },
            "data": null
          }
        ]
      }
    }
@jonnydgreen
Copy link
Collaborator

Hi, thanks for reporting (and for the workaround)! Would you be interested in submitting a PR for this?

@jonnydgreen jonnydgreen added bug Something isn't working good first issue Good for newcomers labels Aug 29, 2022
@ziimakc
Copy link
Author

ziimakc commented Aug 29, 2022

No.

@peterc1731 peterc1731 linked a pull request Mar 2, 2023 that will close this issue
@TimShilov
Copy link

Just encountered this issue with the nullable Object and the directiveValidation: false workaround isn't working for some reason (and is not viable for me anyway as I use directives quite extensively).

I can see that PR is waiting for a review for over 6 months already. I have tested the #67 locally and it seems to be working just fine, I have not noticed any issues. Is there any reason why the PR isn't merged yet? Any help needed?

@jonnydgreen
Copy link
Collaborator

Hey @TimShilov , thank you for your offer of help! This PR dropped off my radar, apologies for this! The only thing blocking the merging is the resolution of one of the open thread which I think is okay to resolve, but if you have any ideas, I'm all ears! I'll aim to get this PR merged once everyone is happy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants