微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GraphQl 联合输入类型

如何解决GraphQl 联合输入类型

在 HotChocolate 中,我有一个这样的查询类型

// 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 个选项)并且没有一个指向可能实现的链接。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。