Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 类型SubSelectRequired的验证错误:字段的类型null需要子选择_Graphql_Graphql Java - Fatal编程技术网

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

Graphql 类型SubSelectRequired的验证错误:字段的类型null需要子选择,graphql,graphql-java,Graphql,Graphql Java,我正在处理一个graphql问题,在这个问题上,我得到了以下请求错误 { customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") { id firstName lastName carsInterested } } "message": "Validation error of type SubSelectionRequired: Sub selection required for type null

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

{
  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'",
下面是我的模式

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
}
我有一个CustomerResolver,里面安装了功能卡。它看起来如下

@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());
    }
}
@组件
公共类CustomerResolver实现GraphQLResolver{
私人最终转托管转托管;
公共CustomerResolver(CarRepository carRepo){this.carRepo=carRepo;}
已测试的公共列表车辆(客户){
返回carRepo.getCarsInterested(customer.getId());
}
}
当我查询没有“carsInterested”的客户时,它工作正常。知道我为什么会犯这个错误吗


感谢

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

您请求的是
carsInterested
,它会返回
车辆列表
,因此您需要指定还需要返回哪些
Car
字段:

{
  customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") {
    id
    firstName
    lastName
    carsInterested {
      # one or more Car fields here
    }
  }
}