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

Validation error of type SubSelectionRequired: Sub selection required for type null of field

我正在处理一个 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 函数 carsInterested in it.It 如下所示

@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' 的情况下查询客户时,它工作正常。知道为什么我会收到此错误吗?

谢谢

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

您正在请求 carsInterested,其中 returns 是 Cars 的列表,因此您还需要指定要返回的 Car 字段:

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