首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >类型SubSelectionRequired的验证错误:字段的类型null需要子选择

类型SubSelectionRequired的验证错误:字段的类型null需要子选择
EN

Stack Overflow用户
提问于 2020-01-02 03:33:31
回答 1查看 12.7K关注 0票数 22

我正在处理一个graphql问题,在这个问题上,我得到了以下请求错误

代码语言:javascript
复制
{
  customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") {
    id
    firstName
    lastName
    carsInterested
  }
}

 "message": "Validation error of type SubSelectionRequired: Sub selection required for type null of field carsInterested @ 'customer/carsInterested'",

下面是我的方案

代码语言:javascript
复制
type Customer {
  id: ID!
  firstName: String!
  lastName: String!
  # list of cars that the customer is interested in
  carsInterested: [Car!]

}

type Query {
  # return 'Customer'
  customer(id: ID!): Customer
}

我在it.It中有一个带有函数carsInterested的CustomerResolver,如下所示

代码语言:javascript
复制
@Component
public class CustomerResolver implements GraphQLResolver<Customer> {

    private final CarRepository carRepo;

    public CustomerResolver(CarRepository carRepo) {this.carRepo = carRepo;}

    public List<Car> carsInterested(Customer customer) {
        return carRepo.getCarsInterested(customer.getId());
    }
}

当我在没有'carsInterested‘的情况下查询客户时,它工作正常。你知道为什么我会得到这个错误吗?

谢谢

EN

Stack Overflow用户

回答已采纳

发布于 2020-01-02 05:00:42

请求解析为对象类型(或对象类型列表)的字段时,还必须指定该对象类型上的字段。特定字段(或根)的字段列表称为选择集或子选择,并用一对大括号括起来。

您正在请求carsInterested,它将返回一个Cars列表,因此您需要指定还需要返回哪些Car字段:

代码语言:javascript
复制
{
  customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") {
    id
    firstName
    lastName
    carsInterested {
      # one or more Car fields here
    }
  }
}
票数 41
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59555497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档