Print with debug flags if not production
This commit is contained in:
parent
a117e7c1f4
commit
5ea41a0253
3 changed files with 97 additions and 96 deletions
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\GraphQL\CoroutinePromiseAdapter;
|
||||
use Appwrite\Utopia\Response;
|
||||
use GraphQL\Error\DebugFlag;
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Type;
|
||||
use GraphQL\Validator\Rules\DisableIntrospection;
|
||||
|
@ -64,22 +66,15 @@ App::post('/v1/graphql')
|
|||
* @throws \Exception
|
||||
*/
|
||||
function graphqlRequest(
|
||||
$query,
|
||||
$operationName,
|
||||
$variables,
|
||||
$request,
|
||||
$response,
|
||||
$promiseAdapter,
|
||||
$gqlSchema
|
||||
)
|
||||
string $query,
|
||||
?string $operationName,
|
||||
?array $variables,
|
||||
Appwrite\Utopia\Request $request,
|
||||
Appwrite\Utopia\Response $response,
|
||||
CoroutinePromiseAdapter $promiseAdapter,
|
||||
Type\Schema $gqlSchema
|
||||
): void
|
||||
{
|
||||
/** @var Appwrite\Utopia\Request $request */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Type\Schema $schema */
|
||||
/** @var Utopia\App $utopia */
|
||||
/** @var Utopia\Registry\Registry $register */
|
||||
/** @var \Utopia\Database\Database $dbForProject */
|
||||
|
||||
if ($request->getHeader('content-type') === 'application/graphql') {
|
||||
// TODO: Add getRawContent() method to Request
|
||||
$query = $request->getSwoole()->rawContent();
|
||||
|
@ -94,7 +89,13 @@ function graphqlRequest(
|
|||
$validations = GraphQL::getStandardValidationRules();
|
||||
$validations[] = new QueryComplexity($maxComplexity);
|
||||
$validations[] = new QueryDepth($maxDepth);
|
||||
|
||||
if (App::isProduction()) {
|
||||
$validations[] = new DisableIntrospection();
|
||||
$debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
|
||||
} else {
|
||||
$debugFlags = DebugFlag::NONE;
|
||||
}
|
||||
|
||||
$promise = GraphQL::promiseToExecute(
|
||||
$promiseAdapter,
|
||||
|
@ -109,8 +110,8 @@ function graphqlRequest(
|
|||
$wg = new WaitGroup();
|
||||
$wg->add();
|
||||
$promise->then(
|
||||
function ($result) use ($response, &$output, $wg) {
|
||||
$output = $result->toArray();
|
||||
function ($result) use ($response, &$output, $wg, $debugFlags) {
|
||||
$output = $result->toArray($debugFlags);
|
||||
$wg->done();
|
||||
},
|
||||
function ($error) use ($response, &$output, $wg) {
|
||||
|
|
40
composer.lock
generated
40
composer.lock
generated
|
@ -300,16 +300,16 @@
|
|||
},
|
||||
{
|
||||
"name": "colinmollenhour/credis",
|
||||
"version": "v1.13.0",
|
||||
"version": "v1.13.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/colinmollenhour/credis.git",
|
||||
"reference": "afec8e58ec93d2291c127fa19709a048f28641e5"
|
||||
"reference": "85df015088e00daf8ce395189de22c8eb45c8d49"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/colinmollenhour/credis/zipball/afec8e58ec93d2291c127fa19709a048f28641e5",
|
||||
"reference": "afec8e58ec93d2291c127fa19709a048f28641e5",
|
||||
"url": "https://api.github.com/repos/colinmollenhour/credis/zipball/85df015088e00daf8ce395189de22c8eb45c8d49",
|
||||
"reference": "85df015088e00daf8ce395189de22c8eb45c8d49",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -341,9 +341,9 @@
|
|||
"homepage": "https://github.com/colinmollenhour/credis",
|
||||
"support": {
|
||||
"issues": "https://github.com/colinmollenhour/credis/issues",
|
||||
"source": "https://github.com/colinmollenhour/credis/tree/v1.13.0"
|
||||
"source": "https://github.com/colinmollenhour/credis/tree/v1.13.1"
|
||||
},
|
||||
"time": "2022-04-07T14:57:22+00:00"
|
||||
"time": "2022-06-20T22:56:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
|
@ -481,22 +481,22 @@
|
|||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "7.4.4",
|
||||
"version": "7.4.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8"
|
||||
"reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
|
||||
"reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82",
|
||||
"reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/promises": "^1.5",
|
||||
"guzzlehttp/psr7": "^1.8.3 || ^2.1",
|
||||
"guzzlehttp/psr7": "^1.9 || ^2.4",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/deprecation-contracts": "^2.2 || ^3.0"
|
||||
|
@ -585,7 +585,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/guzzle/issues",
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.4.4"
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.4.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -601,7 +601,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-06-09T21:39:15+00:00"
|
||||
"time": "2022-06-20T22:16:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
|
@ -689,16 +689,16 @@
|
|||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee"
|
||||
"reference": "13388f00956b1503577598873fffb5ae994b5737"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/83260bb50b8fc753c72d14dc1621a2dac31877ee",
|
||||
"reference": "83260bb50b8fc753c72d14dc1621a2dac31877ee",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737",
|
||||
"reference": "13388f00956b1503577598873fffb5ae994b5737",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -722,7 +722,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.3-dev"
|
||||
"dev-master": "2.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -784,7 +784,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/psr7/issues",
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.3.0"
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.4.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -800,7 +800,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-06-09T08:26:02+00:00"
|
||||
"time": "2022-06-20T21:43:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "influxdb/influxdb-php",
|
||||
|
|
|
@ -19,7 +19,7 @@ use Utopia\Registry\Registry;
|
|||
use Utopia\Route;
|
||||
use Utopia\Validator;
|
||||
|
||||
use function \Co\go;
|
||||
use function Co\go;
|
||||
|
||||
class Builder
|
||||
{
|
||||
|
@ -174,8 +174,7 @@ class Builder
|
|||
Validator|callable $validator,
|
||||
bool $required,
|
||||
array $injections
|
||||
): Type
|
||||
{
|
||||
): Type {
|
||||
$validator = \is_callable($validator)
|
||||
? \call_user_func_array($validator, $utopia->getResources($injections))
|
||||
: $validator;
|
||||
|
@ -211,8 +210,8 @@ class Builder
|
|||
$utopia,
|
||||
$validator->getValidator(),
|
||||
$required,
|
||||
$injections)
|
||||
);
|
||||
$injections
|
||||
));
|
||||
break;
|
||||
case 'Utopia\Validator\Numeric':
|
||||
case 'Utopia\Validator\Integer':
|
||||
|
@ -277,8 +276,7 @@ class Builder
|
|||
Response $response,
|
||||
Database $dbForProject,
|
||||
Document $user,
|
||||
): Schema
|
||||
{
|
||||
): Schema {
|
||||
$apiSchema = self::buildAPISchema($utopia, $request, $response);
|
||||
$db = self::buildCollectionsSchema($utopia, $request, $response, $dbForProject, $user);
|
||||
|
||||
|
@ -329,6 +327,10 @@ class Builder
|
|||
$methodName = $namespace . \ucfirst($route->getLabel('sdk.method', ''));
|
||||
$responseModelNames = $route->getLabel('sdk.response.model', "none");
|
||||
|
||||
if ($responseModelNames === "none") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$responseModels = \is_array($responseModelNames)
|
||||
? \array_map(static fn($m) => $response->getModel($m), $responseModelNames)
|
||||
: [$response->getModel($responseModelNames)];
|
||||
|
@ -390,8 +392,7 @@ class Builder
|
|||
Request $request,
|
||||
Response $response,
|
||||
mixed $route,
|
||||
): callable
|
||||
{
|
||||
): callable {
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $route, $args, $context, $info) {
|
||||
// Mutate the original request object to match route
|
||||
|
@ -424,8 +425,7 @@ class Builder
|
|||
Response $response,
|
||||
Database $dbForProject,
|
||||
?Document $user = null,
|
||||
): array
|
||||
{
|
||||
): array {
|
||||
$start = microtime(true);
|
||||
|
||||
$userId = $user?->getId();
|
||||
|
@ -438,11 +438,13 @@ class Builder
|
|||
|
||||
$wg = new WaitGroup();
|
||||
|
||||
while (!empty($attrs = Authorization::skip(fn() => $dbForProject->find(
|
||||
while (
|
||||
!empty($attrs = Authorization::skip(fn() => $dbForProject->find(
|
||||
'attributes',
|
||||
limit: $limit,
|
||||
offset: $offset
|
||||
)))) {
|
||||
)))
|
||||
) {
|
||||
$wg->add();
|
||||
$count += count($attrs);
|
||||
go(function () use ($utopia, $request, $response, $dbForProject, &$collections, &$queryFields, &$mutationFields, $limit, &$offset, $attrs, $userId, $wg) {
|
||||
|
@ -520,8 +522,7 @@ class Builder
|
|||
Response $response,
|
||||
Database $dbForProject,
|
||||
string $collectionId
|
||||
): callable
|
||||
{
|
||||
): callable {
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $dbForProject, $collectionId, $type, $args) {
|
||||
try {
|
||||
|
@ -549,8 +550,7 @@ class Builder
|
|||
Response $response,
|
||||
Database $dbForProject,
|
||||
string $collectionId
|
||||
): callable
|
||||
{
|
||||
): callable {
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $dbForProject, $collectionId, $type, $args) {
|
||||
$swoole = $request->getSwoole();
|
||||
|
@ -579,8 +579,7 @@ class Builder
|
|||
Database $dbForProject,
|
||||
string $collectionId,
|
||||
string $method,
|
||||
): callable
|
||||
{
|
||||
): callable {
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $dbForProject, $collectionId, $method, $type, $args) {
|
||||
$swoole = $request->getSwoole();
|
||||
|
@ -616,8 +615,7 @@ class Builder
|
|||
Response $response,
|
||||
Database $dbForProject,
|
||||
string $collectionId
|
||||
): callable
|
||||
{
|
||||
): callable {
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $dbForProject, $collectionId, $type, $args) {
|
||||
$swoole = $request->getSwoole();
|
||||
|
@ -649,11 +647,12 @@ class Builder
|
|||
Response $response,
|
||||
callable $resolve,
|
||||
callable $reject,
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
// Drop json content type so post args are used directly
|
||||
if (\array_key_exists('content-type', $swoole->header)
|
||||
&& $swoole->header['content-type'] === 'application/json') {
|
||||
if (
|
||||
\array_key_exists('content-type', $swoole->header)
|
||||
&& $swoole->header['content-type'] === 'application/json'
|
||||
) {
|
||||
unset($swoole->header['content-type']);
|
||||
}
|
||||
|
||||
|
@ -673,6 +672,7 @@ class Builder
|
|||
|
||||
$utopia->execute($route, $request);
|
||||
} catch (\Throwable $e) {
|
||||
\var_dump($e->getMessage());
|
||||
$reject($e);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue