Update promise result output
This commit is contained in:
parent
e3824170b1
commit
2ee5762bc7
|
@ -3,6 +3,7 @@
|
|||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
use GraphQL\Error\DebugFlag;
|
||||
use GraphQL\Executor\ExecutionResult;
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Type;
|
||||
use GraphQL\Validator\Rules\DisableIntrospection;
|
||||
|
@ -62,6 +63,7 @@ App::post('/v1/graphql')
|
|||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
function graphqlRequest(
|
||||
$query,
|
||||
|
@ -85,17 +87,14 @@ function graphqlRequest(
|
|||
$query = $request->getSwoole()->rawContent();
|
||||
}
|
||||
if (empty($query)) {
|
||||
throw new Exception('No query supplied.', 400, Exception::GRAPHQL_NO_QUERY);
|
||||
throw new Exception('No query supplied.', 400, Exception::GRAPHQL_NO_QUERY);
|
||||
}
|
||||
|
||||
$debugFlags = App::isDevelopment()
|
||||
? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE | DebugFlag::RETHROW_INTERNAL_EXCEPTIONS
|
||||
: DebugFlag::NONE;
|
||||
|
||||
// Roughly equivalent to 200 REST requests of work per GraphQL request
|
||||
$maxComplexity = App::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', 200);
|
||||
|
||||
// Maximum nested query depth. Limited to 3 as we don't have more than 3 levels of data relationships
|
||||
$maxDepth = App::getEnv('_APP_GRAPHQL_MAX_QUERY_DEPTH', 3);
|
||||
|
||||
$validations = GraphQL::getStandardValidationRules();
|
||||
|
@ -112,25 +111,20 @@ function graphqlRequest(
|
|||
validationRules: $validations
|
||||
);
|
||||
|
||||
// Blocking wait while queries resolve
|
||||
$output = [];
|
||||
$wg = new WaitGroup();
|
||||
$wg->add();
|
||||
$promise->then(
|
||||
function ($result) use ($response, $debugFlags, $wg) {
|
||||
$result = $result->toArray($debugFlags);
|
||||
\var_dump("Result:" . $result);
|
||||
if (isset($result['errors'])) {
|
||||
$response->json(['data' => [], ...$result]);
|
||||
$wg->done();
|
||||
return;
|
||||
}
|
||||
$response->json(['data' => $result]);
|
||||
function ($result) use ($response, $debugFlags, &$output, $wg) {
|
||||
$output = $result->toArray($debugFlags);
|
||||
$wg->done();
|
||||
},
|
||||
function ($error) use ($response, $wg) {
|
||||
$response->text(\json_encode(['errors' => [\json_encode($error)]]));
|
||||
function ($error) use ($response, &$output, $wg) {
|
||||
$output = ['errors' => [$error]];
|
||||
$wg->done();
|
||||
}
|
||||
);
|
||||
$wg->wait();
|
||||
|
||||
$response->json($output);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue