ZeroQL icon indicating copy to clipboard operation
ZeroQL copied to clipboard

Mutation inputs are generated as optional despite being non-nullable in schema when using "Request" syntax

Open be1223 opened this issue 1 year ago • 0 comments

Describe the bug

When using "Request" syntax, the generated graphql is specifying that the mutation's input is not-nullable when the schema has the input for the same mutation as non-nullable.

This is not the case when using a lambda, in this case the nullability of the input in the generated graphql is correct.

This may also happen with queries, but I've only been using mutations.

How to Reproduce

Define a mutation request with a non-nullable input, it should produce graphql with an optional input.

public sealed record CreateFoo(FooInput Input) : GraphQL<Mutation, int>
{
  public override int Excecute(Mutation query) => query.CreateFoo(Input, static x => x.Id);
}

Expected behavior

Should produce the following correct graphql:

mutation createFoo($input: FooInput!) { id }

Instead produces:

mutation createFoo($input: FooInput) { id }

The same operation using a lambda:

var variables = new { input = new FooInput("Test") }
var id = await client.Mutation(variables, static (v, m) => m.createFoo(v.input, s => s.Id));

This lambda does produce the following:

mutation ($input: FooInput!) { createFoo(input: $input) { id } }

The GraphqQL schema that fails


type Foo {
  id: Int!
}

type FooInput {
  name: String!
}

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

Screenshots

If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • Nuget package version 6.1.1
  • IDE: Visual Studio
  • OS: Windows 11
  • .Net Version tested on both 6.0.416 and 8.0.100

be1223 avatar Feb 14 '24 10:02 be1223