Graphqlbundle: [Overblog\GraphQLBundle\Annotation\Arg] The default is always a string.

Created on 7 Aug 2020  路  8Comments  路  Source: overblog/GraphQLBundle

Q | A
-- | --
Bug report? | yes
Feature request? | no
BC Break report? | no
RFC? | no
Version/Branch | 0.12

bug

Most helpful comment

@sratefiniaina, the bug is fixed. The fix will be available in 0.12.9.

All 8 comments

Can you provide an example please?

Yes,
In my Query definition i have this arg :
@GQL\Arg(name="enabled", type="Boolean", default="false")
But if I do not provide arg from the graphql side, the value is always true.
And when I look at the file var/graqphl/QueryType.php I have this
'args' => [ [ 'name' => 'enabled', 'type' => Type::boolean(), 'description' => null, 'defaultValue' => 'false',],],

@sratefiniaina it should be default=false (without quotes)

@murtukov when i do this, value is null and in var/grqphql/QueryType.php :
'args' => [ [ 'name' => 'enabled', 'type' => Type::boolean(), 'description' => null,],],

Hey guys! I'll look into this tonight or tomorrow.

Hey, OK thanks

@Vincz, the bug comes from loose comparison, which you btw often use in your code.

The method, that causes the issue is located in src/Config/Parser/AnnotationParser.php:

private static function getArgs(array $args = null, \ReflectionMethod $method = null): array
{
    $config = [];
    if ($args && !empty($args)) {
        foreach ($args as $arg) {
            $config[$arg->name] = ['type' => $arg->type]
                + ($arg->description ? ['description' => $arg->description] : [])
                + ($arg->default ? ['defaultValue' => $arg->default] : []);
        }
    } elseif ($method) {
        $config = self::guessArgs($method);
    }

    return $config;
}

the $arg->default and $arg->description are skipped, if value is false, "", 0 or null.

These conditions should be as follows:

+ (null !== $arg->description ? ['description' => $arg->description] : [])
+ (null !== $arg->default ? ['defaultValue' => $arg->default] : []);

But in the PHP >= 7.4, if the properties description and default have type hints, then it should be:

+ (isset($arg->description) ? ['description' => $arg->description] : [])
+ (isset($arg->default) ? ['defaultValue' => $arg->default] : []);

The file src/Config/Parser/AnnotationParser.php is full of loose comparisons.

@sratefiniaina, the bug is fixed. The fix will be available in 0.12.9.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JuanWilde picture JuanWilde  路  4Comments

tjuenger picture tjuenger  路  3Comments

VincentClair picture VincentClair  路  5Comments

SebastienTainon picture SebastienTainon  路  3Comments

Vincz picture Vincz  路  3Comments