Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set null to field in graphql?

We use graphql on our project and use graphql-java 2.3.0 (we plan to update but it is not possible at the moment).

I'm trying to perform such mutation:

  mutation {
    UPDATE_User(

      id:3,
      type: null
    ) {id}
  }

Response:

{
  "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
}
like image 512
Don_Quijote Avatar asked Oct 18 '22 08:10

Don_Quijote


1 Answers

Null keyword is a relatively new addition to the GraphQL spec, and the graphql-java version you're using doesn't yet have it implemented. In fact, even 3.0.0 still doesn't have it. The soon-to-be-released 4.0 will have support for the null keyword.
And the reason it is treated as an enum is because unquoted strings are normally enums, null being the only exception. This is also explained in this issue.

like image 86
kaqqao Avatar answered Jan 04 '23 06:01

kaqqao