Right now it's not possible to set an input type to be both nullable and required. Is there a reason why? I would have expected to be able to do the following:
field: stringArg({}) // -> field: string;
field: stringArg({nullable: true}) // -> field: string | null; actually returning field?: string | null;
field: stringArg({nullable: true, required: false}) // -> field?: string | null;
field: stringArg({required: false}) // -> field?: string;
Am I missing anything?
If the field can receive null, that want to say that the field is not required. The nullable and required are opposites.
I guess my confusion is because of undefined in javascript. I was expecting that if I set the field nullable and required the user of the api would have to explicitly set a value or null. Just omitting the value would result on an error.
@gabrielbusarello
The nullable and required are opposites.
Generally, they are not mutually exclusive.
This tiny difference could be shown, as an example, in a case of mutation for updateSomething with PATCH semantic, when Something has a nullable field.
In this case undefined means "this request does nothing with the field" and null means "set the field to null".
Hi folks,
The root problem here is that GraphQL doesn't differentiate _nullability_ from _optionality_. Nullability in GraphQL expresses both concepts, so you can't define a field both required and nullable. There's unfortunately nothing we can really do. Closing now!
Most helpful comment
@gabrielbusarello
Generally, they are not mutually exclusive.
This tiny difference could be shown, as an example, in a case of mutation for
updateSomethingwith PATCH semantic, whenSomethinghas a nullable field.In this case
undefinedmeans "this request does nothing with the field" andnullmeans "set the field tonull".