简体   繁体   English

使用graphql模式语言的嵌套查询

[英]Nested queries with graphql schema language

I have the following in my buildSchema: 我的buildSchema中包含以下内容:

type User {
  id: ID
  firstname: String
  age : Int
  company : Company
}

type Company {
  id: ID
  name: String
  description : String
}


type RootQuery {
  user(id: ID): User
}

When making this request: 发出此请求时:

user(id:"1"){
  firstname,
  company{
    id,
    name
  }
}

company is returning a null value: 公司返回一个空值:

{
  "data": {
    "user": {
      "firstname": "Jhoni",
      "company": null
    }
  }
}

How can I get the company value? 我如何获得公司价值?

The problem here will be to do with what data is coming into your query. 这里的问题将与查询中包含哪些数据有关。 The execution itself is successful, but you are not getting the company data for some reason. 执行本身是成功的,但是由于某种原因您没有获得公司数据。

To debug this, I would look at what data is actually returned in your resolver for the user query by the request. 为了调试此问题,我将查看解析器中实际返回了哪些数据,以供用户查询该请求。 It could be the reference ID parameter is not linking to any results in where you store company details. 可能是参考ID参数未链接到您存储公司详细信息的任何结果。

I guess one other possibility is that you may have may not pass back the company data into a parameter named 'company', again, looking at the object that is returned to the resolver for 'user' before it is returned by the function should give you an idea of what's not matching up. 我猜还有另一种可能性,就是您可能没有将公司数据传递回名为“ company”的参数,再次,在函数返回之前,查看返回给“用户”的解析器的对象应该给出您会发现什么不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM