基于来自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
?