1. Go to this page and download the library: Download kauanslr/graphthing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kauanslr / graphthing example snippets
use Kauanslr\GraphThing\Traits\MakeGraphQLRequests;
class TestMyGraphQL extends TestCase
{
use MakeGraphQLRequests;
/** @var Endpoint */
protected $endpoint = '/your_graphql_endpoint' //Default '/graphql';
public function test_my_first_mutation_endpoint() {
// Parametros para mutação
$params = [
'field' => 'My first endpoint test',
];
// Campos para serem retornados
$query = ['field_1','field_2', 'field_3'];
// Campos retornados pela query
$fields = $this->graphqlMutate('mutationName', $params, $query);
// Verifica se todos os campos solicitados foram retornados
$this->assertGraphQLFields($fields);
}
public function test_my_sub_queries_endpoint() {
// Os parâmetros para a query principal
$queryParams = [];
// Campos para serem retornados
$query = [
'field_1',
'field_2',
'subQueryName' => [
'params' => [
'sub_query_param' => 'value'
],
'sub_field_1',
'sub_field_2',
'sub_field_3',
]
];
// Campos retornados pela query
$fields = $this->graphqlQuery('queryName', $params, $query, $headers);
// Verifica se todos os campos solicitados foram retornados
$this->assertGraphQLFields($fields);
}
}
use Kauanslr\GraphThing\Traits\MakeGraphQLRequests;
class TestMyGraphQL extends TestCase
{
use MakeGraphQLRequests;
/** @var Endpoint */
protected $endpoint = '/your_graphql_endpoint' //Default '/graphql';
public function test_my_first_mutation_endpoint() {
// Parametros para mutação
$params = [];
// Campos para serem retornados
$query = ['field_1'];
// Campos retornados pela query
$fields = $this->graphqlMutate('mutationName', $params, $query);
// Retorna uma instancia de \Illuminate\Foundation\Testing\TestResponse
$response = $this->graphql->getResponse();
$response->assertStatusCode(403);
}
}
use Kauanslr\GraphThing\Traits\MakeGraphQLRequests;
class TestMyGraphQL extends TestCase
{
use MakeGraphQLRequests;
/** @var Endpoint */
protected $endpoint = '/your_graphql_endpoint' //Default '/graphql';
public function test_my_first_mutation_endpoint() {
// MUtation parameters
$params = [
'field' => 'My first endpoint test',
];
// To return fields
$query = ['field_1','field_2', 'field_3'];
// Get the query result
$fields = $this->graphqlMutate('mutationName', $params, $query);
// Check if requested fields is was returned
$this->assertGraphQLFields($fields);
}
public function test_my_sub_queries_endpoint() {
// Principal query parameters
$queryParams = [];
// Requesting fields
$query = [
'field_1',
'field_2',
'subQueryName' => [
'params' => [
'sub_query_param' => 'value'
],
'sub_field_1',
'sub_field_2',
'sub_field_3',
]
];
// Get query results
$fields = $this->graphqlQuery('queryName', $params, $query, $headers);
// Check if requested fields is was returned
$this->assertGraphQLFields($fields);
}
}