【发布时间】:2020-04-20 15:44:03
【问题描述】:
我正在处理一个 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
}
我确实有一个带有功能 cars 的 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”的客户时,它可以正常工作。知道为什么我会收到此错误吗?
谢谢
【问题讨论】:
标签: graphql graphql-java