首页 > 解决方案 > 错误:使用 Graphql 在 Spring Boot 中不可为空的类型是“ID”

问题描述

我刚刚设计了一个使用Graphql的Spring Boot示例。

我尝试通过id更新部门,但在id部分出现错误。

这是我的错误消息,如下所示。

The field at path '/updateDepartment/hospital/id' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value.  The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'ID' within parent type 'Hospital'

这是我的突变查询变量片段,如下所示。

mutation updateDepartment($departmentInput: DepartmentInput!) {
  updateDepartment(id: 10,department: $departmentInput){
    name
    hospital{
      id
    }
  }
}

{
  "departmentInput": {
    "name": "Department 10 Update",
    "hospitalId": 3
  }
}

这是我的项目链接:项目链接

我该如何解决这个错误?

标签: javaspring-bootgraphql

解决方案


这是我的解决方案

突变

mutation updateDepartment($departmentInput: DepartmentInput!) {
  updateDepartment(id: 10,department: $departmentInput){
    name
  }
}

查询变量

{
  "departmentInput": {
    "name": "Department 10 Update",
    "hospitalId": 3
  }
}

推荐阅读