higherkindness / mu-haskell

Mu (μ) is a purely functional framework for building micro services.
http://higherkindness.io/mu-haskell/
Apache License 2.0
333 stars 19 forks source link

Not working: nullable variables used as optional arguments #344

Open rynoV opened 1 year ago

rynoV commented 1 year ago

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 commented 1 year ago

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...