我正在处理一个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
}
我在it.It中有一个带有函数carsInterested的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());
}
}
当我在没有'carsInterested‘的情况下查询客户时,它工作正常。你知道为什么我会得到这个错误吗?
谢谢
发布于 2020-01-02 05:00:42
请求解析为对象类型(或对象类型列表)的字段时,还必须指定该对象类型上的字段。特定字段(或根)的字段列表称为选择集或子选择,并用一对大括号括起来。
您正在请求carsInterested
,它将返回一个Cars
列表,因此您需要指定还需要返回哪些Car
字段:
{
customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") {
id
firstName
lastName
carsInterested {
# one or more Car fields here
}
}
}
https://stackoverflow.com/questions/59555497
复制相似问题