在这个post上,作者做了一个示例助手,使用的包是Lighthouse
public function graphql(string $query)
{
return $this->post('/graphql', [
'query' => $query
]);
}所以可以像这样使用它:
$response = $this->graphql("{articles(first: 10) { edges { node { title } } } }");但是我可以在突变上实现它吗?例如,我有一个突变:
type Mutation {
sampleMutation(
id: ID!
)
}我不确定如何在突变上做到这一点。
发布于 2019-06-27 03:21:56
测试突变是可能的。
在最新版本的灯塔中,您现在可以将一个名为MakesGraphQLRequests的特征添加到测试类中。
取自他们的docs的是关于如何创建突变测试的以下示例。
public function testCreatePost(): void
{
/** @var \Illuminate\Foundation\Testing\TestResponse $response */
$response = $this->postGraphQL([
'query' => '
mutation CreatePost($title: String!) {
createPost(title: $title) {
id
}
}
',
'variables' => [
'title' => 'Automatic testing proven to reduce stress levels in developers'
],
]);
}您得到的response对象将包含json结果,就像您的突变一样。因此,在这里,您可以像通常使用Laravel一样创建任何json断言。
在他们的文档中,有关于如何验证json的some examples。
免责声明:我是这篇文章的作者。
https://stackoverflow.com/questions/52982212
复制相似问题