overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
783 stars 221 forks source link

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

Closed Vincz closed 1 year ago

Vincz commented 1 year ago

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.

Vincz commented 1 year ago

ping @mcg-web

deeky666 commented 12 months ago

@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