1
0
Fork 0
mirror of synced 2024-07-06 23:21:05 +12:00

feat: refactoring

This commit is contained in:
Christy Jacob 2021-03-16 20:04:43 +05:30
parent 4c49fb1b05
commit 60b863311b
3 changed files with 44 additions and 82 deletions

View file

@ -245,26 +245,29 @@ class Builder {
$responseModel = $response->getModel($responseModelName);
self::createTypeMapping($responseModel, $response);
$type = self::$typeMapping[$responseModel->getType()];
$description = $route->getDesc();
$args = self::getArgs($route->getParams(), $utopia);
$resolve = function ($type, $args, $context, $info) use (&$register, $route) {
$utopia = $register->get('__app');
$utopia->setRoute($route)
->execute($route, $args);
$response = $register->get('__response');
$result = $response->getPayload();
if (self::isModel($result, $response->getModel(Response::MODEL_ERROR)) || self::isModel($result, $response->getModel(Response::MODEL_ERROR_DEV))) {
var_dump("***** There has been an exception.. *****");
unset($result['trace']);
// var_dump($result);
throw new Exception($result['message'], $result['code']);
}
return $result;
};
$field = [
'type' => $type,
'description' => $route->getDesc(),
'description' => $description,
'args' => $args,
'resolve' => function ($type, $args, $context, $info) use (&$register, $route) {
$utopia = $register->get('__app');
$utopia->setRoute($route)
->execute($route, $args);
$response = $register->get('__response');
$result = $response->getPayload();
if (self::isModel($result, $response->getModel(Response::MODEL_ERROR)) || self::isModel($result, $response->getModel(Response::MODEL_ERROR_DEV))) {
var_dump("***** There has been an exception.. *****");
unset($result['trace']);
// var_dump($result);
throw new Exception($result['message'], $result['code']);
}
return $result;
}
'resolve' => $resolve
];
if ($method == 'GET') {

View file

@ -6,52 +6,50 @@ use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideClient;
use Tests\E2E\Scopes\SideServer;
class GraphQLBase extends Scope
{
use ProjectCustom;
use SideClient;
use SideServer;
public function testListUsers()
{
/**
* Test for SUCCESS
*/
// $projectId = $this->getProject()['$id'];
$projectId = '60394d47b252a';
$collectionId = "6048c40b28392";
public function createKey(string $name, array $scopes): string {
$projectId = $this->getProject()['$id'];
$query = "
query listDocuments(\$collectionId: String!){
database_listDocuments (collectionId: \$collectionId) {
sum
documents
mutation createKey(\$projectId: String!, \$name: String!, \$scopes: [Json]!){
projects_createKey (projectId: \$projectId, name: \$name, scopes: \$scopes) {
id
name
scopes
secret
}
}
";
$variables = [
'collectionId' => $collectionId
"projectId" => $projectId,
"name" => $name,
"scopes" => $scopes
];
$graphQLPayload = [
"query" => $query,
"variables" => $variables
];
$response = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
$key = $this->client->call(Client::METHOD_POST, '/graphql', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
]), $graphQLPayload);
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console'
], $graphQLPayload);
var_dump($response['headers']);
var_dump($response['body']);
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertEquals($key['headers']['status-code'], 201);
$this->assertNull($key['body']['errors']);
$this->assertIsArray($key['body']['data']);
$this->assertIsArray($key['body']['data']['projects_createKey']);
return $key['body']['data']['projects_createKey']['secret'];
}
}

View file

@ -7,12 +7,12 @@ use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
use function PHPSTORM_META\type;
class GraphQLServerTest extends Scope
{
use SideServer;
use ProjectCustom;
use GraphQLBase;
public function testCreateCollection(): array {
$projectId = $this->getProject()['$id'];
@ -388,45 +388,6 @@ class GraphQLServerTest extends Scope
$this->assertIsArray($countries['body']['data']);
$this->assertNull($countries['body']['data']['locale_getCountries']);
}
public function createKey(string $name, array $scopes): string {
$projectId = $this->getProject()['$id'];
$query = "
mutation createKey(\$projectId: String!, \$name: String!, \$scopes: [Json]!){
projects_createKey (projectId: \$projectId, name: \$name, scopes: \$scopes) {
id
name
scopes
secret
}
}
";
$variables = [
"projectId" => $projectId,
"name" => $name,
"scopes" => $scopes
];
$graphQLPayload = [
"query" => $query,
"variables" => $variables
];
$key = $this->client->call(Client::METHOD_POST, '/graphql', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console'
], $graphQLPayload);
$this->assertEquals($key['headers']['status-code'], 201);
$this->assertNull($key['body']['errors']);
$this->assertIsArray($key['body']['data']);
$this->assertIsArray($key['body']['data']['projects_createKey']);
return $key['body']['data']['projects_createKey']['secret'];
}
}