错误:使用 Graphql 的 Spring Boot 中不可为空的类型是“ID" [英] Error : The non-nullable type is 'ID' in Spring Boot with the usage of Graphql

查看:53
本文介绍了错误:使用 Graphql 的 Spring Boot 中不可为空的类型是“ID"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚设计了一个使用 GraphqlSpring Boot 示例.

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

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

路径/updateDepartment/hospital/id"中的字段被声明为非空类型,但检索数据所涉及的代码错误地返回了空值.graphql 规范要求将父字段设置为 null,或者如果该字段不可为 null,则它会将 null 冒泡到其父字段,依此类推.不可为空类型是父类型医院"中的ID"

这是我的变异查询变量片段,如下所示.

mutation updateDepartment($departmentInput: DepartmentInput!) {更新部门(ID:10,部门:$departmentInput){姓名医院{身份证}}}{部门输入":{名称":部门 10 更新",医院 ID":3}}

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

我该如何修复该错误?

解决方案

这是我的解决方案

突变

mutation updateDepartment($departmentInput: DepartmentInput!) {更新部门(ID:10,部门:$departmentInput){姓名}}

查询变量

<代码>{部门输入":{名称":部门 10 更新",医院 ID":3}}

I just devised an example of Spring Boot with the usage of Graphql.

I tried to update the department by id but I got an error in id part.

Here is my error message which is shown below.

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'

Here are my mutation and query variables snippets which is shown below.

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

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

Here is my project link : Project Link

How can I fix that error?

解决方案

Here is my solution

Mutation

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

Query Variables

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

这篇关于错误:使用 Graphql 的 Spring Boot 中不可为空的类型是“ID"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆