Код: Выделить всё
"Cannot query field \"products\" on type \"Query\". Did you mean \"product\"?"[img]https://i.sstatic .net/LyRXq.png[/img]
Мой ProductQuery.php
Код: Выделить всё
namespace App\GraphQL\Queries;
use App\Models\Product;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Support\Query;
class ProductQuery extends Query
{
protected $attributes = [
'name' => 'product',
'description' => 'A query'
];
/**
* Return type for these query
* @return Type
*/
public function type(): Type
{
return GraphQL::type('Product');
}
/**
* Passed arguments for this query
* @return array
*/
public function args(): array
{
return [
'slug' => [
'name' => 'slug',
'type' => Type::nonNull(Type::string()),
'rules' => ['required']
],
];
}
/**
* Resolve Query to get pass an information
* @param mixed $root
* @param array $args
* @return Product
*/
public function resolve($root, array $args): Product
{
return Product::where('slug', $args['slug'])->first();
}
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/66869378/graphql-returns-the-error-message-cannot-query-field-when-i-try-to-get-all[/url]