问题描述
// 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; }
}
当我运行应用程序时出现以下错误
1. Unable to infer or resolve a schema type from the type reference `Input: Filter`.
filterContent (categoryCode: "All",filters: [{type: "boolean",isTrue: true},{type: "numberrange",min: 10,max: 60}]) {
id
}
解决方法
目前似乎没有实现。
这是an issue in hotchocolate repository。目前(2021 年 7 月)它是开放的并且有“积压”标签,所以我可以假设输入联合还没有实现。
这是 hotChocolate 开发者之一的a tweet,他说
我们正在为热巧克力实施 #graphql oneof 规范提案 12...让输入联合来:)
顺便说一下,还有另一个指向 discussion 的链接,关于输入联合问题的可能实现。因此,根据这一点,有 7 种不同的想法如何更改规范,1 个获胜者(第 7 个选项)并且没有一个指向可能实现的链接。