Skip to content

The inputType "String!" of a field in an annotated input type is being ignored when update is set to true. #371

Closed

Description

@hjerichen

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!')]
    public string $important;
}

The output will be String and not String!.

Is this intended behavior?
I would expect that my specified input type is used.

Activity

  1. oojacoboo commented on Aug 26, 2021

    @oojacoboo
    Collaborator

    @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.

  2. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    As explained by @devmaslov here, this is the intended behavior.
    I will check if its easy to implement in this PR #466

  3. oojacoboo commented on Apr 22, 2022

    @oojacoboo
    Collaborator

    @Lappihuan The example given here should default to String! anyway, since it's not nullable typed in PHP, regardless of the annotation.

  4. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    @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.

  5. oojacoboo commented on Apr 22, 2022

    @oojacoboo
    Collaborator

    @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.

  6. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    @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.

  7. Lappihuan commented on Apr 24, 2022

    @Lappihuan
    Contributor

    This would be supported with this commit:
    1a21b83

  8. oojacoboo commented on Jun 12, 2022

    @oojacoboo
    Collaborator

    Closing - assuming this may be resolved in version 6.0. If not, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions