ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.25k stars 744 forks source link

Error on generating code for non nullable ICollection<Guid> #4739

Open mwilde opened 2 years ago

mwilde commented 2 years ago

Describe the bug

If you have a DTO (maybe record) with a non nullable property ICollection<Guid> MyValues than the generated schema.graphql looks great: input MyDtoInput { myValues: [UUID!]! }

But the code generator for StrawberryShake throws an error on generating process: Non-Nullable-Feld "_value_myValues" muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie eine Deklaration von "Feld" als Nullable.

To get the process working the only possibility is to mark ICollection<Guid>? MyValues as nullable.

Steps to reproduce

  1. Create DTO public record MyDto( ICollection<Guid> MyValues);
  2. Create DTO public record MyInput( MyDto MyValue)
  3. Update schema with dotnet graphql update
  4. Create mutation mutation SendMyInput( $dto:MyInput!){ sendMyInput( input: $dto ) }
  5. The code generator throws the error

Relevant log output

Non-Nullable-Feld "_value_myValues" muss beim Beenden des Konstruktors einen Wert ungleich NULL enthalten. Erwägen Sie eine Deklaration von "Feld" als Nullable.

Product

Hot Chocolate, Strawberry Shake

Version

12.6.0

PascalSenn commented 2 years ago

@mwilde can you share query and schema?

mwilde commented 2 years ago

@PascalSenn here is my schema and the mutation:

schema { mutation: Mutation }

type Mutation { setMyValue(input: SetMyValueInput!): SetMyValuePayload! }

type SetMyValuePayload { errors: [UserError!]! }

scalar UUID

type UserError { message: String! }

input SetMyValueInput { myValue: MyDtoInput! }

input MyDtoInput { myIds: [UUID!]! }

mutation SetMyValue( $dto:SetMyValueInput!){ setMyValue( input: $dto ){ errors { message } } }

mwilde commented 2 years ago

@PascalSenn the same error occurs if you have a collection of type Enum.

mwilde commented 2 years ago

@PascalSenn what is the status here?

mwilde commented 2 years ago

@PascalSenn what is the status here?

QuentonB commented 2 years ago

I'm running into the same issue on version 12.12.1, is there any update @PascalSenn @tobias-tengler ?

nesherhh commented 1 month ago

Have this problem with 13.9.12 Error in English: "error CS8618: Non-nullable field '_value_ids' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable."

Workaround: Create a partial class with the same name and default constructor. Disable warning with #pragma

public partial class MyDtoInput
{
#pragma warning disable CS8618
  public MyDtoInput() {}
#pragma warning restore CS8618
}