GraphQL.Parser.SourceException:``id''不是类型为``User''的字段

时间:2018-09-18 08:16:13

标签: c# asp.net-mvc graphql

我正在尝试学习graphql,所以我决定编写一个小应用程序,我在代码中做错了什么?我需要帮助。请帮助,谢谢。

var schema = GraphQL<TestContext>.CreateDefaultSchema(() => new TestContext());
    var user = schema.AddType<User>();
    user.AddField(u => u.Id);
    user.AddField(u => u.Name);
    user.AddField(u=>u.Account);            
    user.AddField("totalUsers", (db, u) => db.Users.Count());           
    schema.AddType<Account>().AddAllFields();
    schema.AddListField("users", db => db.Users);            
    schema.Complete();
 var query = @"{
    users {
    id
    name
    account {
        id 
        name
        paid
    }
    totalUsers
  }}";

    var gql = new GraphQL<TestContext>(schema);
    var dict = gql.ExecuteQuery(query);
    return Json(dict, JsonRequestBehavior.AllowGet);//

模型

用户

public class User
{
  public int Id { get; set; }
  public string Name { get; set; }
  public int AccountId { get; set; }
  public virtual Account Account { get; set; }
}

帐户

 public class Account
 {
    public int Id { get; set; }
    public string Name { get; set; }
    public bool Paid { get; set; }
 }

0 个答案:

没有答案