admin管理员组文章数量:1131160
My configuration Query.yaml
Query:
type: object
config:
fields:
allUsers:
type: "[User]!" # Array type Users
resolve: "@=query('App\\Domain\\User\\Api\\GraphQL\\Query\\UserQuery::resolveAllUsers')"
description: "Отримати список усіх користувачів."
user:
type: "User"
args:
id:
type: "ID!"
description: "ID user."
resolve: "@=query('App\\Domain\\User\\Api\\GraphQL\\Query\\UserQuery::resolveUserById', [args['id']])"
description: "Found user by ID."
Class UserQuery.php
<?php
declare(strict_types=1);
namespace App\Domain\User\Api\GraphQL\Query;
use App\Domain\User\Repository\UserRepository;
use Overblog\GraphQLBundle\Definition\Resolver\QueryInterface;
class UserQuery implements QueryInterface
{
private array $users;
public function __construct(private readonly UserRepository $userRepository)
{
$this->users = [
['id' => 1, 'name' => 'John Doe', 'email' => '[email protected]'],
['id' => 2, 'name' => 'Jane Smith', 'email' => '[email protected]'],
];
}
public function resolveAllUsers(): array
{
return $this->users;
}
public function resolveUserById($id): ?array
{
foreach ($this->users as $user) {
if ($user['id'] === (int)$id) {
return $user;
}
}
return null;
}
}
For the directory App\Domain\User\Api\GraphQL
, auto-discovery is configured as follows:
App\Domain\User\Api\GraphQL\:
resource: '../src/Domain/User/Api/GraphQL'
Running the command php bin/console cache:clear
successfully registers my services in GraphQL Query Services.
However, when GraphQLBundle processes a response, it expects an alias like 'AppDomainUserApiGraphQLQueryUserQuery'
.
After inspecting the generated files, I found the following call:
return $services->query("AppDomainUserApiGraphQLQueryUserQuery::resolveUserById", [0 => $args["id"]]);
Here, the backslashes (\
) were removed during generation.
To resolve this issue, I had to modify the configuration in Query.yaml
from:
resolve: "@=query('App\\Domain\\User\\Api\\GraphQL\\Query\\UserQuery::resolveAllUsers')"
to:
resolve: "@=query('App\\\\Domain\\\\User\\\\Api\\\\GraphQL\\\\Query\\\\UserQuery::resolveAllUsers')"
After making this change, the functionality started working. Is there perhaps a better solution to this problem?
本文标签:
版权声明:本文标题:php - GraphQLBundle: Unknown resolver with alias "AppDomainUserApiGraphQLQueryUserQuery::resolveUserById" (ver 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736736136a1950264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论