feat: refactoring
This commit is contained in:
parent
4c49fb1b05
commit
60b863311b
3 changed files with 44 additions and 82 deletions
|
@ -245,13 +245,10 @@ class Builder {
|
|||
$responseModel = $response->getModel($responseModelName);
|
||||
self::createTypeMapping($responseModel, $response);
|
||||
$type = self::$typeMapping[$responseModel->getType()];
|
||||
$description = $route->getDesc();
|
||||
$args = self::getArgs($route->getParams(), $utopia);
|
||||
|
||||
$field = [
|
||||
'type' => $type,
|
||||
'description' => $route->getDesc(),
|
||||
'args' => $args,
|
||||
'resolve' => function ($type, $args, $context, $info) use (&$register, $route) {
|
||||
$resolve = function ($type, $args, $context, $info) use (&$register, $route) {
|
||||
$utopia = $register->get('__app');
|
||||
$utopia->setRoute($route)
|
||||
->execute($route, $args);
|
||||
|
@ -264,7 +261,13 @@ class Builder {
|
|||
throw new Exception($result['message'], $result['code']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
};
|
||||
|
||||
$field = [
|
||||
'type' => $type,
|
||||
'description' => $description,
|
||||
'args' => $args,
|
||||
'resolve' => $resolve
|
||||
];
|
||||
|
||||
if ($method == 'GET') {
|
||||
|
|
|
@ -6,35 +6,30 @@ 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;
|
||||
|
||||
public function testListUsers()
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
|
||||
// $projectId = $this->getProject()['$id'];
|
||||
|
||||
$projectId = '60394d47b252a';
|
||||
$collectionId = "6048c40b28392";
|
||||
use SideServer;
|
||||
|
||||
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 = [
|
||||
|
@ -42,16 +37,19 @@ class GraphQLBase extends Scope
|
|||
"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'];
|
||||
}
|
||||
|
||||
}
|
|
@ -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'];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue