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 doesn't honor default enum values #1979

Closed
andrew-kolesnikov opened this issue Oct 21, 2022 · 6 comments · Fixed by #2003
Closed

validation doesn't honor default enum values #1979

andrew-kolesnikov opened this issue Oct 21, 2022 · 6 comments · Fixed by #2003
Assignees

Comments

@andrew-kolesnikov
Copy link

andrew-kolesnikov commented Oct 21, 2022

Our particular spec has a mutation input containing channel: SimpleStringEnum! = WEB but to pass validation, router expects input to still have that field explicitly set.

Steps to reproduce the behavior:
{"input":{"channel":"MOBILE",...}}} passes validation
{"input":{...}}} doesn't with a cryptic error response: {“errors”:[{“message”:“invalid type for variable: ‘input’“,”locations”:[],“path”:null,“extensions”:{“type”:“ValidationInvalidTypeVariable”,“name”:“input”}}]}

@andrew-kolesnikov
Copy link
Author

@Geal the problematic mutation uses fragments, and likely to be related to the work done for #1367

@Geal Geal self-assigned this Oct 24, 2022
@Geal
Copy link
Contributor

Geal commented Oct 24, 2022

@andrew-kolesnikov could you show a reproducible test case?

With this schema:

enum Terminal {
    WEB,
    MOBILE
}
type Query{
    test: String
}
type Mutation {
    page(channel: Terminal! = WEB): String
}

and this query:

mutation GetPage($terminal: Terminal) {
    page(channel: $terminal)
}

right now it works, but if you could show me something with the same shape as your query that would help

@Geal
Copy link
Contributor

Geal commented Oct 25, 2022

ok I see the error with

mutation GetPage($terminal: Terminal!) {
    page(channel: $terminal)
}

@Geal
Copy link
Contributor

Geal commented Oct 25, 2022

hmm no, that fails because the operation itself actually needs a value. Can you show an example query?

@andrew-kolesnikov
Copy link
Author

andrew-kolesnikov commented Oct 25, 2022

Using the following schema:

type Mutation{
    foo(input: FooInput!): FooResponse!
}

input FooInput {
  enumWithDefault: EnumWithDefault! = WEB
}

enum EnumWithDefault {
  WEB
  MOBILE
}

Request the following:

mutation foo($input: FooInput!) { 
    foo (input: $input) { 
    __typename
}}
{"input":{}}

Observe failed validation:

{
    "errors": [
        {
            "message": "invalid type for variable: 'input'",
            "locations": [],
            "path": null,
            "extensions": {
                "type": "ValidationInvalidTypeVariable",
                "name": "input"
            }
        }
    ]
}

Yet {"input":{"enumWithDefault":"MOBILE"}} seems to pass validation

@Geal
Copy link
Contributor

Geal commented Oct 25, 2022

alright, thanks!

@Geal Geal removed the triage label Oct 26, 2022
@Geal Geal added this to the v1-NEXT milestone Oct 26, 2022
@Geal Geal closed this as completed in #2003 Nov 2, 2022
Geal pushed a commit that referenced this issue Nov 2, 2022
Fix #1979

When validating variables, we should use default values for object
fields if applicable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants