Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests & arguments transformer when data is not set #1073

Merged
merged 6 commits into from
Jan 3, 2023
Merged

Fix tests & arguments transformer when data is not set #1073

merged 6 commits into from
Jan 3, 2023

Conversation

Vincz
Copy link
Collaborator

@Vincz Vincz commented Dec 13, 2022

When data for an input doesn't exist (ie. The property is not set in the data), use the default value of the input property or null if is doesn't have one.

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Documented? no
License MIT

When a input object is used in conjunction with the ArgumentsTransformer, if the data doesn't contain the property, use the default one from the input object instead of null.

For example:

<?php
final class MyInput
{
    public $field1;

    public $field2 = "default_me";
}
?>

If the submitted data doesn't include the field2 property, the input instance will be left untouched and $field2 will equals default_me instead of null.

When data for an input doesn't exist (ie. The property is not set in the data), use the default value of the input property or null if is doesn't have one.
@Vincz Vincz requested a review from mcg-web December 13, 2022 12:36
@Vincz Vincz changed the title Fix arguments transformer when data is not set Fix tests & arguments transformer when data is not set Dec 13, 2022
@Vincz Vincz requested a review from murtukov December 13, 2022 12:37
@Vincz
Copy link
Collaborator Author

Vincz commented Dec 23, 2022

ping @mcg-web

Copy link
Member

@mcg-web mcg-web left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Vincz !

@Vincz Vincz merged commit e182fc9 into overblog:master Jan 3, 2023
@deeky666
Copy link
Contributor

@Vincz @mcg-web this breaks typed Properties where no default value is set. Just encountered this while upgrading to v1.0:

<?php

namespace App\Input;

use Overblog\GraphQLBundle\Annotation as GQL;

#[GQL\Input]
final class MyInput
{
    #[GQL\Field]
    public ?string $field;
}

Throws Error: Typed property App\\Input\\MyInput::$field must not be accessed before initialization

See also: https://3v4l.org/9KReD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants