如何将graphql中的字段设置为null?

Don*_*ote 6 graphql graphql-java

我们在项目中使用 graphql,并使用 graphql-java 2.3.0(我们计划更新,但目前不可能)。

我正在尝试执行这样的突变:

  mutation {
    UPDATE_User(

      id:3,
      type: null
    ) {id}
  }
Run Code Online (Sandbox Code Playgroud)

回复:

{
  "errors": [
    {
      "validationErrorType": "WrongType",
      "message": "Validation error of type WrongType: argument value EnumValue{name='null'} has wrong type",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "errorType": "ValidationError"
    }
  ],
  "data": null
}
Run Code Online (Sandbox Code Playgroud)

kaq*_*qao 3

Null 关键字是 GraphQL 规范中相对较新的补充,您使用的 graphql-java 版本尚未实现它。事实上,即使是3.0.0仍然没有。即将发布的4.0将支持null关键字。
它被视为枚举的原因是因为不带引号的字符串通常是枚举,null这是唯一的例外。本期对此也进行了解释。