Open Makapashev opened 2 years ago
via expression info
info | A GraphQL\Type\Definition\ResolveInfo object of current resolver
my code is
#[GQL\Provider]
class MovementReportResolver implements QueryInterface
{
public function __construct(private MovementReportRepositoryInterface $movementReportRepository)
{
}
/**
* @return MovementReportRecord[]
*/
#[GQL\Query(name: 'movementReport', type: '[MovementReportRecord!]!', resolve: "query('App\\\\GraphQL\\\\Query\\\\Warehouse\\\\MovementReportResolver', args, info)")]
#[GQL\Arg(name: 'first', type: 'Int')]
#[GQL\Arg(name: 'sort', type: '[MovementReportSort!]')]
#[GQL\Arg(name: 'filter', type: '[MovementReportFilter!]')]
#[GQL\Access(value: "hasPermission('movement', 'READ')")]
public function __invoke(Argument $args, ResolveInfo $info): array
{
$filter = $args['filter'];
$sort = $args['sort'];
$first = $args['first'];
return $this->movementReportRepository->report(
array_keys($info->getFieldSelection(16)),
$filter,
$sort,
$first
);
}
}
via expression info
info | A GraphQL\Type\Definition\ResolveInfo object of current resolver
my code is
#[GQL\Provider] class MovementReportResolver implements QueryInterface { public function __construct(private MovementReportRepositoryInterface $movementReportRepository) { } /** * @return MovementReportRecord[] */ #[GQL\Query(name: 'movementReport', type: '[MovementReportRecord!]!', resolve: "query('App\\\\GraphQL\\\\Query\\\\Warehouse\\\\MovementReportResolver', args, info)")] #[GQL\Arg(name: 'first', type: 'Int')] #[GQL\Arg(name: 'sort', type: '[MovementReportSort!]')] #[GQL\Arg(name: 'filter', type: '[MovementReportFilter!]')] #[GQL\Access(value: "hasPermission('movement', 'READ')")] public function __invoke(Argument $args, ResolveInfo $info): array { $filter = $args['filter']; $sort = $args['sort']; $first = $args['first']; return $this->movementReportRepository->report( array_keys($info->getFieldSelection(16)), $filter, $sort, $first ); } }
Thanks, but I got an error message Failed to parse GraphQL metadata from file "/var/www/src/QueryType.php"
.
Do you know how to solve this?
@calvera My QueryType
file contains:
<?php
declare(strict_types=1);
namespace App;
use Overblog\GraphQLBundle\Annotation as GQL;
#[GQL\Type]
final class QueryType
{
}
Hello! In my project i'm using attribute as mapping type. How can I get list of queried fields in my resolver?