0

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

4

1 回答 1

0

解决方案在这里讨论: https ://github.com/graphql-dotnet/graphql-dotnet/issues/593

于 2018-03-10T19:41:10.393 回答