如何在 Api 平台中测试 GraphQL 端点?

问题描述 投票:0回答:0

我在我的 Api 平台应用程序 v3.1(和 Symfony 6)中使用 GraphQL,我正在尝试测试我的不同查询和突变,但我不知道如何将查询传递给请求。

我已经做了什么:

final class Test extends ApiTestCase
{
    public function setUp(): void
    {
        parent::setUp();
    }

    public function testProfile(): void
    {
        $client = self::createClient();
 
        $fixtures = $this->databaseTool
            ->loadFixtures([
                UserTestFixtures::class
            ])
            ->getReferenceRepository();
        
        $user = $fixtures->getReference('user_operator');

        $token = $this->getToken([
            'username' => $user->getEmail(),
            'password' => 'S3cret'
        ]);
 
        $response = $client->request('GET', 'api/graphql', [
            'headers' => [
                'Content-Type' => 'application/json',
                'Authorization => 'Bearer ' . $token
            ],
            'extra' => [
                'parameters' => [
                    'operations' => '{
                        "query": "query getProfile {
                            profileUser {
                                id
                                firstName
                                lastName
                                email
                            }
                        }"
                    }'
                ]
            ]
        ]);
    }
}

所以我的问题是:如何将 GraphQL 查询传递给请求?

在上面的示例中,我有以下错误消息:“GraphQL 查询无效”。

谢谢

graphql phpunit api-platform.com symfony6
© www.soinside.com 2019 - 2024. All rights reserved.