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

Bug when parsing dynamic query string #141

Closed
dilab opened this issue Apr 19, 2017 · 4 comments
Closed

Bug when parsing dynamic query string #141

dilab opened this issue Apr 19, 2017 · 4 comments

Comments

@dilab
Copy link

dilab commented Apr 19, 2017

Test Field

namespace App\Graphql\Schema\Field;


use Youshido\GraphQL\Config\Field\FieldConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Field\AbstractField;
use Youshido\GraphQL\Type\Scalar\IntType;
use Youshido\GraphQL\Type\Scalar\StringType;

class TestField extends AbstractField
{
    public function getType()
    {
        return new StringType();
    }

    public function resolve($value, array $args, ResolveInfo $info)
    {
       return var_export($args, true);
    }

    public function build(FieldConfig $config)
    {
        $config->addArgument('id', new IntType());
    }
}

Query with dynamic variables

Query string

query Test($id: Int) {
  test(id: $id)
}

Query variable

{}

Result

{
  "data": {
    "test": "array (\n  'id' => NULL,\n)"
  }
}

Bug

IMO, in this case, "id" should not be set because client-side has never sent the "id" variable. By setting a default NULL value cause confusion and lead to bugs.

@dilab dilab changed the title Bug when parsing query string Bug when parsing dynamic query string Apr 19, 2017
@dilab
Copy link
Author

dilab commented Apr 19, 2017

More reference to back up
Secion 5.e
https://facebook.github.io/graphql/#CoerceArgumentValues()

@dilab
Copy link
Author

dilab commented Apr 20, 2017

After digging further, I realised that youshido/graphql will set Boolean input to false as the default value if it is not provided.

<?php

namespace App\Graphql\Schema\Field;


use Youshido\GraphQL\Config\Field\FieldConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Field\AbstractField;
use Youshido\GraphQL\Type\Scalar\BooleanType;
use Youshido\GraphQL\Type\Scalar\IntType;
use Youshido\GraphQL\Type\Scalar\StringType;

class TestField extends AbstractField
{
    public function getType()
    {
        return new StringType();
    }

    public function resolve($value, array $args, ResolveInfo $info)
    {
        return var_export($args, true);
    }

    public function build(FieldConfig $config)
    {
        $config->addArgument('id', new BooleanType());
    }
}

Output

{
  "data": {
    "test": "array (\n  'id' => false,\n)"
  }
}

This should prove that it is indeed a bug?

@dilab
Copy link
Author

dilab commented Apr 24, 2017

@viniychuk is this ticket going anywhere? Would appreciate your input.

@viniychuk
Copy link
Member

viniychuk commented Apr 24, 2017

@dilab I believe it should throw an error because you actually specified a variable on the client side and never sent it.
update After spending some time – I need to get some input back. It's technically a correct query, but all together with variables it's not.
I've made a change that is producing an error with a details about the query.

Jalle19 pushed a commit to digiaonline/GraphQL that referenced this issue Oct 28, 2017
This reverts commit 38e7e4e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants