feat: refactoring
This commit is contained in:
parent
4c49fb1b05
commit
60b863311b
3 changed files with 44 additions and 82 deletions
|
@ -245,26 +245,29 @@ class Builder {
|
||||||
$responseModel = $response->getModel($responseModelName);
|
$responseModel = $response->getModel($responseModelName);
|
||||||
self::createTypeMapping($responseModel, $response);
|
self::createTypeMapping($responseModel, $response);
|
||||||
$type = self::$typeMapping[$responseModel->getType()];
|
$type = self::$typeMapping[$responseModel->getType()];
|
||||||
|
$description = $route->getDesc();
|
||||||
$args = self::getArgs($route->getParams(), $utopia);
|
$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 = [
|
$field = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'description' => $route->getDesc(),
|
'description' => $description,
|
||||||
'args' => $args,
|
'args' => $args,
|
||||||
'resolve' => function ($type, $args, $context, $info) use (&$register, $route) {
|
'resolve' => $resolve
|
||||||
$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;
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($method == 'GET') {
|
if ($method == 'GET') {
|
||||||
|
|
|
@ -6,52 +6,50 @@ use Tests\E2E\Client;
|
||||||
use Tests\E2E\Scopes\ProjectCustom;
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
use Tests\E2E\Scopes\Scope;
|
use Tests\E2E\Scopes\Scope;
|
||||||
use Tests\E2E\Scopes\SideClient;
|
use Tests\E2E\Scopes\SideClient;
|
||||||
|
use Tests\E2E\Scopes\SideServer;
|
||||||
|
|
||||||
class GraphQLBase extends Scope
|
class GraphQLBase extends Scope
|
||||||
{
|
{
|
||||||
use ProjectCustom;
|
use ProjectCustom;
|
||||||
use SideClient;
|
use SideServer;
|
||||||
|
|
||||||
public function testListUsers()
|
public function createKey(string $name, array $scopes): string {
|
||||||
{
|
$projectId = $this->getProject()['$id'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for SUCCESS
|
|
||||||
*/
|
|
||||||
|
|
||||||
// $projectId = $this->getProject()['$id'];
|
|
||||||
|
|
||||||
$projectId = '60394d47b252a';
|
|
||||||
$collectionId = "6048c40b28392";
|
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
query listDocuments(\$collectionId: String!){
|
mutation createKey(\$projectId: String!, \$name: String!, \$scopes: [Json]!){
|
||||||
database_listDocuments (collectionId: \$collectionId) {
|
projects_createKey (projectId: \$projectId, name: \$name, scopes: \$scopes) {
|
||||||
sum
|
id
|
||||||
documents
|
name
|
||||||
|
scopes
|
||||||
|
secret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
$variables = [
|
$variables = [
|
||||||
'collectionId' => $collectionId
|
"projectId" => $projectId,
|
||||||
|
"name" => $name,
|
||||||
|
"scopes" => $scopes
|
||||||
];
|
];
|
||||||
|
|
||||||
$graphQLPayload = [
|
$graphQLPayload = [
|
||||||
"query" => $query,
|
"query" => $query,
|
||||||
"variables" => $variables
|
"variables" => $variables
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
$key = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||||
'origin' => 'http://localhost',
|
'origin' => 'http://localhost',
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $projectId,
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||||
]), $graphQLPayload);
|
'x-appwrite-project' => 'console'
|
||||||
|
], $graphQLPayload);
|
||||||
|
|
||||||
var_dump($response['headers']);
|
$this->assertEquals($key['headers']['status-code'], 201);
|
||||||
var_dump($response['body']);
|
$this->assertNull($key['body']['errors']);
|
||||||
$this->assertEquals($response['headers']['status-code'], 200);
|
$this->assertIsArray($key['body']['data']);
|
||||||
|
$this->assertIsArray($key['body']['data']['projects_createKey']);
|
||||||
|
|
||||||
|
return $key['body']['data']['projects_createKey']['secret'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,12 +7,12 @@ use Tests\E2E\Scopes\ProjectCustom;
|
||||||
use Tests\E2E\Scopes\Scope;
|
use Tests\E2E\Scopes\Scope;
|
||||||
use Tests\E2E\Scopes\SideServer;
|
use Tests\E2E\Scopes\SideServer;
|
||||||
|
|
||||||
use function PHPSTORM_META\type;
|
|
||||||
|
|
||||||
class GraphQLServerTest extends Scope
|
class GraphQLServerTest extends Scope
|
||||||
{
|
{
|
||||||
use SideServer;
|
use SideServer;
|
||||||
use ProjectCustom;
|
use ProjectCustom;
|
||||||
|
use GraphQLBase;
|
||||||
|
|
||||||
public function testCreateCollection(): array {
|
public function testCreateCollection(): array {
|
||||||
$projectId = $this->getProject()['$id'];
|
$projectId = $this->getProject()['$id'];
|
||||||
|
@ -388,45 +388,6 @@ class GraphQLServerTest extends Scope
|
||||||
$this->assertIsArray($countries['body']['data']);
|
$this->assertIsArray($countries['body']['data']);
|
||||||
$this->assertNull($countries['body']['data']['locale_getCountries']);
|
$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'];
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue