当前位置: 首页 > 知识库问答 >
问题:

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

麻烨
2023-03-14

我正在处理一个图形ql问题,我得到以下请求错误

{
  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
}

我确实有一个内置功能卡的客户解决方案。情况如下

@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());
    }
}

当我查询客户没有汽车感兴趣,它正常工作。知道我为什么会出现这个错误吗?

谢谢

共有1个答案

万俟浩
2023-03-14

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

您请求的car返回一个列表,其中包含Cars,因此您需要指定您还希望返回的Car字段:

{
  customer(id: "5ed6092b-6924-4d31-92d0-b77d4d777b47") {
    id
    firstName
    lastName
    carsInterested {
      # one or more Car fields here
    }
  }
}
 类似资料:
  • 在java应用程序中调用GraphQL查询时出现以下错误- “说明”:“accountQuery字段的帐户类型需要子选择”,“validationErrorType”:“需要子选择”,“queryPath”:[“accountQuery”], 这是我的图式 模式{查询:查询} 类型查询{accountQuery(nbr:String):Account} 键入帐户{ nbr:String name:

  • 我是新手。我正在开发一个测验应用程序,并拥有以下三个dart文件: 主要的飞奔 question.dart answer.dart 当我在android studio中的android上运行应用程序时,出现以下错误: ══╡ 小部件库捕获的异常╞═══════════════════════════════════════════ 生成MyApp时引发了以下类型的错误(脏,状态:_MyAppSta

  • 我是一名spring boot学习者,所以我一直在尝试创建一些基本的spring boot应用程序。我试图运行开发的应用程序时出错。 我的错误是[[https://i.stack.imgur.com/oyQDi.png][1]][1] java: ItemDetails.java:[软件包名称:io.ajithan.springbootstarter.model] ItemResponse.jav

  • 结构没有问题。spring boot可以扫描UserMapper,但不能扫描UserService。我试着给我的UserService@Mapper组件,然后它就可以被扫描了。但我不知道如何使用其他方法进行扫描。我尝试了@服务,但不起作用。

  • 请看一下这段代码。最后一行出现了一个错误,因为我传递的是一个“索引”而不是一个资源。我以为是皮毛的问题,试图压制它。然后我注意到只有在构建发布时才会出现这个错误。它在构建调试时工作良好。我完全一无所知。谁能告诉我我做错了什么。

  • 我在应用程序部署期间进行Hibernate验证时遇到了一些问题。我有两个类,Frame和FrameReleasePlan,它们在OneToOne关系中关联。在数据库端,关系是单向的。frame_release_planss表有一个NUMERIC(19,0)类型的“frame_id”列,它是一个指向frame表“id”列的外键。当我尝试部署时,模式验证失败并出现错误: 无法生成Hibernate S