Q | A
-- | --
Bug report? | yes
Feature request? | no
BC Break report? | no
RFC? | no
Version/Branch | 0.12
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.
Most helpful comment
@sratefiniaina, the bug is fixed. The fix will be available in 0.12.9.