[GraphQL] Cannot convert to a nullable type in default create mutation #5165
Unanswered
Dev-TeamGS
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
Context:
I implemented a custom type converter (that implement the TypeConverterInterface) where I customize the type of a specific property.
The problem I face is on the default "create" mutation: I cannot set my input property as nullable.
I'm creating a list of my specific type like so:
Since
GraphQLType::listOf(...)
creates aListOfType
object that implements the NullableType interface, I expect the type on the Schema to be:[myType]
. But the type I get is[myType]!
, forcing the input property to be filled.I figured out the problem comes from the FieldsBuilder that forces any class that implement the NullableType to be NonNullable (notice the the "!" that invert the check of the instance):
core/src/Core/GraphQl/Type/FieldsBuilder.php
Lines 514 to 516 in 4fe0821
I can understand the idea behind having required input property, but it would be interesting as well to have them optional (with default value), especially if the type is manually set on the TypeConverter.
Is that a mistake or maybe a feature I didn't understand ?
Beta Was this translation helpful? Give feedback.
All reactions