You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The inputType "String!" of a field in an annotated input type is being ignored when update is set to true. #371
When an input type ist specified with update: true, it makes all fields optional (as stated in the documentation).
It even does it when I specifically say it should be non optional through the inputType in a Field Annotation.
#[Input(update: true)]
class UserInput
{
#[Field(inputType: 'String!')]
publicstring$important;
}
The output will be String and not String!.
Is this intended behavior?
I would expect that my specified input type is used.
@devmaslov any input on this? I haven't used the Input annotation yet. Based on what @hjerichen is saying here, I'd tend to agree that it should be able to be overridden for any given field.
@oojacoboo no, update makes everything nullable regardless of what php says.
this is actually intended and a really cool feature as described here
Note that update: true argument for UpdateUserInput. It should be used when input type is used for a partial update, It makes all fields optional and removes all default values from thus prevents setting default values via setters or directly to public properties. In example above if you use the class as UpdateUserInput and set only username the other ones will be ignored. In PHP 7 they will be set to null, while in PHP 8 they will be in not initialized state - this can be used as a trick to check if user actually passed a value for a certain field.
@Lappihuan yep, overlooked that it was an update here. I guess this is the right approach. I do wonder if we'd benefit from another attribute on the Field annotation to make it "required". Or maybe that's at least worth looking into/considering.
@oojacoboo i think type forcing as tested above should be fine, it would follow the current workflow of how to overwrite something between PHP types and GQL Types.
Activity
oojacoboo commentedon Aug 26, 2021
@devmaslov any input on this? I haven't used the
Inputannotation yet. Based on what @hjerichen is saying here, I'd tend to agree that it should be able to be overridden for any given field.Lappihuan commentedon Apr 22, 2022
As explained by @devmaslov here, this is the intended behavior.
I will check if its easy to implement in this PR #466
oojacoboo commentedon Apr 22, 2022
@Lappihuan The example given here should default to
String!anyway, since it's not nullable typed in PHP, regardless of the annotation.Lappihuan commentedon Apr 22, 2022
@oojacoboo no, update makes everything nullable regardless of what php says.
this is actually intended and a really cool feature as described here
oojacoboo commentedon Apr 22, 2022
@Lappihuan yep, overlooked that it was an
updatehere. I guess this is the right approach. I do wonder if we'd benefit from another attribute on theFieldannotation to make it "required". Or maybe that's at least worth looking into/considering.Lappihuan commentedon Apr 22, 2022
@oojacoboo i think type forcing as tested above should be fine, it would follow the current workflow of how to overwrite something between PHP types and GQL Types.
Lappihuan commentedon Apr 24, 2022
This would be supported with this commit:
1a21b83
oojacoboo commentedon Jun 12, 2022
Closing - assuming this may be resolved in version 6.0. If not, please reopen.