基于graphql-dotnet的示例:
public class Droid
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Query
{
[GraphQLMetadata("hero")]
public Droid GetHero()
{
return new Droid { Id = "123", Name = "R2-D2" };
}
}
var schema = Schema.For(@"
interface Node {
id: String
}
type Droid implements Node {
id: String
name: String
}
type Query {
hero: Node
}
", _ => {
_.Types.Include<Query>();
});
var result = schema.Execute(_ =>
{
_.Query = "{ hero { id ... on Droid { name } } }";
});
我需要为接口ResolveType
定义Node
方法。我发现了这种方式:
_.Types.For("Node").ResolveType = obj => { /* needs to return an ObjectGraphType object here */ };
ResolveType
获取Droid
个对象作为输入,但需要ObjectGraphType
个对象!在 NodeJS 中,我可以将解析后的类型作为字符串返回,如“Droid”。
是否有任何解决方法,没有定义继承自ObjectGraphType
的新类?