GraphQl Union input types

Viewed 802

In HotChocolate I have a query type like so

// QueryType.cs
public Task<ContentCategory> FilterContentAsync(string categoryCode, ICollection<Filter> filters, CancellationToken cancellationToken = default)
            => ...;

// Filter.cs
public abstract class Filter
{
    public string Type { get;set; }
}

// BooleanFilter.cs
public class BooleanFilter : Filter
{
    public bool IsTrue { get; set; }
}

// NumberRangeFilter.cs
public class NumberRangeFilter : Filter
{
    public int Min { get; set; }

    public int Max { get; set; }
}

when I run the application I get the following error

1. Unable to infer or resolve a schema type from the type reference `Input: Filter`.

Is the following query supported:

filterContent (categoryCode: "All", filters: [{type: "boolean", isTrue: true}, {type: "numberrange", min: 10, max: 60}]) {
  id
}

1 Answers

Seems that this is not implemented currently.

Here is an issue in hotchocolate repository. Currently (Jul 2021) it is open and have "backlog" label, so I can assume that input unions are not implemented yet.

And here is a tweet of one of developers of hotChocolate, where he says

We are implementing the #graphql oneof spec proposal for Hot Chocolate 12... let the input unions come :)

By the way there is another link to discussion about possible implementations for input union problem. So according to this, there is 7 various ideas how to change the spec, 1 winner (the 7th option) and no one single link to possible implementations.

Related