graphql-to-json-schema icon indicating copy to clipboard operation
graphql-to-json-schema copied to clipboard

"Nullable" fields have wrong type

Open tobias-tengler opened this issue 2 years ago • 1 comments

The difference between a "nullable" and a non-null field is currently handled using the "required" property on the JSON schema object. This is only partly correct, as a nullable field can either be not specified (it is not required) or it can be assigned null.

The required behavior should stay, but if the field is not declared as non-null, the fields should be as follows:

Lists

{
   "type": ["array", "null"]
}

Types

{
   "type":{
      "oneOf":[
         {
            // or whatever the actual type is
            "type":"string"
         },
         {
            "type":"null"
         }
      ]
   }
}

tobias-tengler avatar Aug 07 '21 11:08 tobias-tengler

Have you tried setting the nullableArrayItems option to true as described in the README?

Also, it would help if:

  1. You provided a small sample SDL that will replicate what you're talking about
  2. Provide the output you're seeing
  3. Provide the output you're expecting (you've don that here, thanks!)

newhouse avatar Sep 17 '21 15:09 newhouse