From f11e4313419cc52a5976077c805067011f50bb05 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 26 Feb 2021 03:26:38 +0530 Subject: [PATCH] feat: got locale_getContinents working --- app/controllers/api/graphql.php | 30 ++++++++++++++++++++---------- app/controllers/api/locale.php | 2 ++ app/controllers/shared/api.php | 9 ++++++--- docker-compose.yml | 2 +- src/Appwrite/Utopia/Response.php | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/graphql.php b/app/controllers/api/graphql.php index 0f5f95775..935260579 100644 --- a/app/controllers/api/graphql.php +++ b/app/controllers/api/graphql.php @@ -159,8 +159,6 @@ function getArgType(Validator $validator, bool $required) { function getArgs(array $params) { $args = []; foreach ($params as $key => $value) { - var_dump("Key : ${key}"); - var_dump($value); $args[$key] = [ 'type' => getArgType($value['validator'],!$value['optional']), 'description' => $value['description'], @@ -183,22 +181,33 @@ function buildSchema($utopia, $response) { $methodName = $namespace.'_'.$route->getLabel('sdk.method', ''); $responseModelName = $route->getLabel('sdk.response.model', Response::MODEL_NONE); - var_dump("******************************************"); - var_dump("Model Name : ${responseModelName}"); + // var_dump("******************************************"); + // var_dump("Model Name : ${responseModelName}"); if ( $responseModelName !== Response::MODEL_NONE && $responseModelName !== Response::MODEL_ANY ) { $responseModel = $response->getModel($responseModelName); createTypeMapping($responseModel, $response); + + $args = getArgs($route->getParams()); $fields[$methodName] = [ 'type' => $typeMapping[$responseModel->getType()], 'description' => $route->getDesc(), - 'args' => getArgs($route->getParams()), + 'args' => $args, + 'resolve' => function ($args) use (&$utopia, $route, $response) { + var_dump("************* REACHED RESOLVE *****************"); + var_dump($route); + $utopia->execute($route, $args); + var_dump("********************** ARGS *******************"); + var_dump($args); + var_dump("**************** OUTPUT ************"); + var_dump($response->getPayload()); + return $response->getPayload(); + } ]; - // print_r($fields[$methodName]); - var_dump("Processed route : {$route->getURL()}"); + // var_dump("Processed route : {$route->getURL()}"); } else { - var_dump("Skipping route : {$route->getURL()}"); + // var_dump("Skipping route : {$route->getURL()}"); } } } @@ -232,8 +241,7 @@ App::post('/v1/graphql') ->inject('request') ->inject('response') ->inject('utopia') - ->inject('schema') - ->action(function ($request, $response, $utopia, $schema) { + ->action(function ($request, $response, $utopia) { // Generate the Schema of the server on startup. // Use the routes from utopia and get the params then construct the queries and mutations. @@ -246,6 +254,8 @@ App::post('/v1/graphql') $rootValue = []; $result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variables); $output = $result->toArray(); + var_dump("********** OUTPUT *********"); + var_dump($output); } catch (\Exception $error) { $output = [ 'errors' => [ diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 80826bdc0..d636a6be0 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -190,6 +190,8 @@ App::get('/v1/locale/continents') /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ + var_dump("*************** IN LOCALE ************* "); + $list = $locale->getText('continents'); /* @var $list array */ \asort($list); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8dc0c097c..7611e5928 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -47,9 +47,12 @@ App::init(function ($utopia, $request, $response, $project, $user, $register, $e //TODO make sure we get array here - foreach ($request->getParams() as $key => $value) { // Set request params as potential abuse keys - $timeLimit->setParam('{param-'.$key.'}', (\is_array($value)) ? \json_encode($value) : $value); - } + + var_dump($request->getParams()); + + // foreach ($request->getParams() as $key => $value) { // Set request params as potential abuse keys + // $timeLimit->setParam('{param-'.$key.'}', (\is_array($value)) ? \json_encode($value) : $value); + // } $abuse = new Abuse($timeLimit); diff --git a/docker-compose.yml b/docker-compose.yml index 1831a658e..de2e7773b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -504,7 +504,7 @@ services: graphiql: container_name: graphiql ports: - - '9505:4000' + - '9506:4000' environment: - API_URL=http://localhost/v1/graphql image: npalm/graphiql diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b2203918d..0a89eff2a 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -260,7 +260,7 @@ class Response extends SwooleResponse $output = self::getFilter()->parse($output, $model); } - $this->json(!empty($output) ? $output : new stdClass()); + // $this->json(!empty($output) ? $output : new stdClass()); } /**