-
-
Notifications
You must be signed in to change notification settings - Fork 956
Description
Hi everyone,
Context:
- Symfony 6
- Api-Platform 2.6 with GraphQL
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:
// The method to implement to customize types
public function convertType(...) {
// Customize the type of a specific property to "[myType]"
if(...) {
$type = $this->typesContainer->get("myType");
return GraphQLType::listOf(GraphQLType::getNullableType($type)));
}
return $this->defaultTypeConverter->convertType(...);
}Since GraphQLType::listOf(...) creates a ListOfType 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
| return $forceNullable || !$graphqlType instanceof NullableType || $type->isNullable() || (null !== $mutationName && 'update' === $mutationName) | |
| ? $graphqlType | |
| : GraphQLType::nonNull($graphqlType); |
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 ?