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

Not working: nullable variables used as optional arguments #344

Open
rynoV opened this issue Jan 8, 2023 · 1 comment
Open

Not working: nullable variables used as optional arguments #344

rynoV opened this issue Jan 8, 2023 · 1 comment

Comments

@rynoV
Copy link

rynoV commented Jan 8, 2023

With mu-graphql-0.5.0.3, if I have:

type Mutation {
  updateItemState(newState: String): Item!
}

and I try a mutation like:

mutation test($newState: String) {
  updateItemState(newState: $newState) {
    <field selection>
  }
}

I don't see a way to avoid setting $newState to a string. In the JSON request if I use:

"variables":{}

I get a graphql error:

{
  "errors": [
    {
      "message": "variable 'newState' was not found"
    }
  ]
}

If I instead do:

"variables": {"newState": null}

I get:

{
  "errors": [
    {
      "message": "argument 'newState' was not of right type"
    }
  ]
}

Is this a bug or am I missing something? For my case, preferably "variables":{} would work since that's what my graphql client lib does.

@sfwc
Copy link

sfwc commented Jan 14, 2023

I'm seeing a similar issue using a complex input type. If I have something like

type Mutation {
  createFoo(input: FooInput!): Foo!
}
type FooInput {
  bar: String!
  baz: String
}

and I run

{"query": "mutation { createFoo(input: $input) }", "variables": {"input": {"bar": "?"}}}

I get

{"errors":[{"message":"field 'baz' was not found on type 'FooInput'"}]}

So I guess the query parser just doesn't handle optional arguments, even though the schema parser and type/term system both do (expressing them with Maybe)? I'm trying to work on a fix myself but not finding the query parser code easy to understand...

@rynoV rynoV changed the title Nullable variables used as optional arguments Not working: nullable variables used as optional arguments Jun 6, 2023
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

No branches or pull requests

2 participants