-
-
Notifications
You must be signed in to change notification settings - Fork 568
Closed
Description
We stumbled upon the following situation:
- We have a query which declares Boolean variable with default value.
- This variable is used as an argument for
@include
directive. - When executing query, variable is explictly set to
null
.
In this case, I'd expect to have an exception, as graphql-js
does. Instead, any non-false value is treated as true
.
Simplified example:
$queryType = new ObjectType([
'name' => 'Query',
'fields' => [
'test' => [
'type' => Type::string(),
]
]
]);
$schema = new Schema([
'query' => $queryType
]);
$root = [
'test' => '123'
];
$query = <<<GQL
query Q(\$include: Boolean = false) {
test @include(if: \$include)
}
GQL;
$vars = [
'include' => null,
];
$result = GraphQL::executeQuery($schema, $query, $root, null, $vars);
print_r($result->data);
This code prints:
Array
(
[test] => 123
)
Where equivalent JS code throws:
GraphQLError: Argument "if" of non-null type "Boolean!" must not be null.