GraphQL Requests
GraphQL Requests
When testing a GraphQL endpoint, we set the $schema
property on the test class.
/**
* @var string the GraphQL schema name
*/
protected $schema = 'sandboxes';
The mutation must be stored in a variable for readability in each test.
public function sandboxes_save_object_returns_200(): void
{
$mutation = <<<'GQL'
mutation {
saveSandbox(data: { title: "New Sandbox" }) {
id
title
}
}
GQL;
// ...
}
To run the GraphQL endpoint, call the ->graphql()
method.
public function sandboxes_save_object_returns_200(): void
{
$mutation = <<<'GQL'
mutation {
saveSandbox(data: { title: "New Sandbox" }) {
id
title
}
}
GQL;
$this->actingAsAdmin()
->authenticate()
->graphql($mutation);
}
Last updated