Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected @include behaviour with explicit null paramter #394

Closed
SevInf opened this issue Nov 12, 2018 · 2 comments
Closed

Unexpected @include behaviour with explicit null paramter #394

SevInf opened this issue Nov 12, 2018 · 2 comments
Labels
Milestone

Comments

@SevInf
Copy link
Contributor

SevInf commented Nov 12, 2018

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.
@SevInf
Copy link
Contributor Author

SevInf commented Nov 12, 2018

It looks like #262 resolves it

@vladar vladar added the bug label Apr 21, 2019
@vladar vladar added this to the 14.0 milestone Jun 19, 2019
@vladar
Copy link
Member

vladar commented Aug 26, 2019

This is fixed in master via bf4e7d4

@vladar vladar closed this as completed Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants