Description
This is more of a general questions, but I'm unable to find a good resolution to this issue. Consider the following mutation:
updateProduct(input: {
id!,
name,
price
}) { id }
In this updateProduct
mutation you're requiring an UpdateProductInput
type which has a non-nullable id
property and 2 nullable properties, meaning name
and price
can be passed with the request or not.
Now, with the factory and UpdateProductInput
, I'm unsure of how to handle these in the situation where one or both of, name
and price
could be nullable. This is because, with PHP, we basically need to make these values default to null, due to the factory method being called. Or so I think. Does GraphQLite, default arguments of the method signature to null
if they are not passed in the request?
With PHP 7.4, if we used setters in a factory, we could possibly make use of the uninitialized state with typed properties, or possibly, if the factory used "overloading" on the input type.
At the end of the day, when using input types, which is the recommended way of designing your mutations to add flexibility and mitigate future BC issues, you have no real way of knowing if the property, with a null value, was explicitly set, or defaulted. When taking this to a persistence layer, this clearly presents issues.
I'd love some advice or feedback on this as I'm trying to determine the best way of approaching this issue. Currently I'm thinking it may be best to rely on the uninitialized state for properties within the input types. If the raw request object was accessible, you'd know if the property was passed, and therefore intended to be persisted.