【发布时间】:2019-09-25 17:02:54
【问题描述】:
如何将枚举转换为 GraphQL 使用的 EnumerationGraphType? 这是一个例子来说明我在说什么:
public enum MeetingStatusType
{
Tentative,
Unconfirmed,
Confirmed,
}
public class MeetingDto
{
public string Id { get; set; }
public string Name { get; set; }
public MeetingStatusType Status { get; set; }
}
public class MeetingStatusEnumType : EnumerationGraphType<MeetingStatusType>
{
public MeetingStatusEnumType()
{
Name = "MeetingStatusType";
}
}
public class MeetingType : ObjectGraphType<MeetingDto>
{
public MeetingType()
{
Field(m => m.Id);
Field(m => m.Name, nullable: true);
Field<MeetingStatusEnumType>(m => m.Status); // Fails here
}
}
显然这不起作用,因为没有从MeetingStatusType 到MeetingStatusEnumType 的隐式转换。 In the documentation,他们正在映射的模型将直接依赖于 MeetingStatusEnumType,但是在诸如域类型和对象之类的东西上引入对 GraphQL 的依赖似乎并不好。
我觉得我错过了一种非常简单的方法来注册这个领域,但我一辈子都想不通。任何帮助将不胜感激!
【问题讨论】:
-
您能否显示
Field<T>的定义或确切的错误消息?我只能找到第一个参数是字符串的。 -
出现两个错误:
Cannot implicitly convert type 'MeetingStatusType' to 'MeetingStatusEnumType'Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type这是我正在使用的字段重载的定义:public FieldType Field<TGraphType>(string name, string description = null, QueryArguments arguments = null, Func<ResolveFieldContext<TSourceType>, object> resolve = null, string deprecationReason = null) where TGraphType : IGraphType;
标签: c# .net-core graphql graphql-dotnet