ocaml-graphql-server icon indicating copy to clipboard operation
ocaml-graphql-server copied to clipboard

Nullable defaults args and required default args are impossible to express

Open dwwoelfel opened this issue 5 years ago • 0 comments

There are two use cases of arg defaultValues that can't be expressed with ocaml-graphql-server.

  1. A nullable arg can never be null in the resolver.
  2. A non-null arg can't have a default.

Take the valid graphql schema:

type Query {
  field(argOne: String = "A" argTwo: String! = "B"): String!
}

argTwo can't be expressed with ocaml-graphql-server.

If the resolve function (in js to make it easier to demonstrate what is happening) looks like this:

resolve(_, {argOne, argTwo}) {
  return `${argOne}${argTwo}`
}

A nullable arg can never be null in the resolver:

{
  field(argOne: null)
}
{"field": "B"}

Example of 2:

{
  field(argTwo: null)
}
{"errors": [{"message": "argTwo must be non-null"}]}

dwwoelfel avatar Aug 18 '20 16:08 dwwoelfel