Graphql 类型SubSelectRequired的验证错误:字段的类型null需要子选择
我正在处理一个graphql问题,在这个问题上,我得到了以下请求错误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
{
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
}
}
}