folkloreinc / laravel-graphql

Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.
1.76k stars 233 forks source link

Query Variables Empty #388

Closed diegomengarda closed 6 years ago

diegomengarda commented 6 years ago

Hey guys i'm trying to use query variables in my app but the value of the variables is empty.

Here is my code.

class UsersQuery extends Query
{

    protected $attributes = [
        'name' => 'Users Query',
        'description' => 'A query of users',
        'model' => User::class
    ];

    public function type()
    {
        return GraphQL::paginate('users');
    }

    public function args()
    {
        return [
            'id' => [
                'name' => 'id',
                'type' => Type::int()
            ],
            'limit' => [
                'name' => 'limit',
                'type' => Type::int()
            ],
            'page' => [
                'name' => 'page',
                'type' => Type::int()
            ],
            'filters' => [
                'name' => 'filters',
                'type' => Type::listOf(GraphQL::type('filter'))
            ]
        ];
    }

    public function resolve($root, $args)
    {
        dd('$args', $args);
    }
}
class FilterType extends GraphQLType
{

    protected $inputObject = true;

    protected $attributes = [
        'name' => 'FilterType',
        'description' => 'A type'
    ];

    public function fields()
    {
        return [
            'field' => [
                'name' => 'field',
                'type' => Type::nonNull(Type::string())
            ],
            'rule' => [
                'name' => 'rule',
                'type' => Type::string()
            ],
            'value1' => [
                'name' => 'value1',
                'type' => Type::nonNull(Type::string())
            ],
            'value2' => [
                'name' => 'value2',
                'type' => Type::string()
            ]
        ];
    }
}

Query and result image

I already tried remove the "params" from the query variables but the result was empty too.

Anyone can help me with this problem ?

Thanks!

mfn commented 6 years ago

I'm not sure but a few things pop up to me which look weird…

This is the name of the query for the outside, yet in your example you use fetchUsers? image

Is this filter supposed to be the same? Because the names/cases are different. IMHO both should just be Filter: image

Not sure about the last, but in your Screenshot params is red underlined and you don't use $params in your query.

I could be wrong but on the first glance, things simply look a bit off here.

diegomengarda commented 6 years ago

This config allows me to use the short names My types and queries are registrated like that: config/graphql.php

'types' => [
    'filter' => FilterType::class
]
'query' => [
    'users' => UsersQuery::class
]

And like a said i already tested the query without the "params".

diegomengarda commented 6 years ago

I had to remove the attribute model from UsersQuery to work correctly