1

I can't figure out how to make it so that the elements of the array are non nullable using annotation-based HotChocolate. I'm looking to create a gql schema for my class that looks like:

foos: [Foo!]!

However, at the moment all I've been able to come up with for my class is:

class Bar
{
[GraphQLNonNullType]
public List<Foo> foos {get; set;}
}

I am using C# 9.0

MrMeik
  • 41
  • 4

1 Answers1

1

I solved my problem!

While I was using C# 9, my project was not configured to enforce explicit nullability. I changed my .csproj configuration file to include the line

<Nullable>enable</Nullable>

This has the added benefit of no longer needing to use the [GraphQLNonNullType] attribute anymore. My new code looks like this:

class Bar
{
    public List<Foo> foos {get; set;}
}

Which generates the gql schema I am expecting.

If you don't want to change your entire project settings to achieve the same result, here is another option.

class Bar
{
    #nullable enable
    public List<Foo> foos {get; set;}
}
MrMeik
  • 41
  • 4