Skip to content

Unexpected @include behaviour with explicit null paramter #394

@SevInf

Description

@SevInf

We stumbled upon the following situation:

  1. We have a query which declares Boolean variable with default value.
  2. This variable is used as an argument for @include directive.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions