mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Remove coroutines for easier debug
This commit is contained in:
parent
d95a1b277f
commit
f81e69d7d6
1 changed files with 85 additions and 104 deletions
|
|
@ -6,7 +6,6 @@ use Appwrite\GraphQL\Types\JsonType;
|
||||||
use Appwrite\Utopia\Request;
|
use Appwrite\Utopia\Request;
|
||||||
use Appwrite\Utopia\Response;
|
use Appwrite\Utopia\Response;
|
||||||
use Appwrite\Utopia\Response\Model;
|
use Appwrite\Utopia\Response\Model;
|
||||||
use Co\WaitGroup;
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Error\FormattedError;
|
use GraphQL\Error\FormattedError;
|
||||||
use GraphQL\Type\Definition\ObjectType;
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
|
|
@ -16,7 +15,7 @@ use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Database\Validator\Authorization;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Registry\Registry;
|
use Utopia\Registry\Registry;
|
||||||
use Utopia\Validator;
|
use Utopia\Validator;
|
||||||
|
|
||||||
|
|
@ -278,111 +277,93 @@ class Builder
|
||||||
$mutationFields = [];
|
$mutationFields = [];
|
||||||
$limit = 50;
|
$limit = 50;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$wg = new WaitGroup();
|
|
||||||
|
|
||||||
Authorization::skip(function () use (&$mutationFields, &$queryFields, &$collections, $register, $limit, &$offset, $dbForProject, $wg) {
|
while (!empty($attrs = $dbForProject->find(
|
||||||
while (!empty($attrs = $dbForProject->find(
|
'attributes',
|
||||||
'attributes',
|
[new Query('signed', Query::TYPE_EQUAL, [true]),],
|
||||||
limit: $limit,
|
limit: $limit,
|
||||||
offset: $offset
|
offset: $offset
|
||||||
))) {
|
))) {
|
||||||
$offset += $limit;
|
foreach ($attrs as $attr) {
|
||||||
go(function () use ($attrs, &$mutationFields, &$queryFields, &$collections, $register, $limit, &$offset, $dbForProject, $wg) {
|
$collectionId = $attr->getAttribute('collectionId');
|
||||||
$wg->add();
|
if ($attr->getAttribute('status') !== 'available') {
|
||||||
$nested = new WaitGroup();
|
continue;
|
||||||
foreach ($attrs as $attr) {
|
}
|
||||||
go(function () use ($attr, &$mutationFields, &$queryFields, &$collections, $register, $limit, &$offset, $dbForProject, $nested) {
|
$key = $attr->getAttribute('key');
|
||||||
$nested->add();
|
$type = $attr->getAttribute('type');
|
||||||
$collectionId = $attr->getAttribute('collectionId');
|
$array = $attr->getAttribute('array');
|
||||||
if ($attr->getAttribute('status') !== 'available') {
|
$required = $attr->getAttribute('required');
|
||||||
$nested->done();
|
$escapedKey = str_replace('$', '_', $key);
|
||||||
return;
|
$collections[$collectionId][$escapedKey] = [
|
||||||
}
|
'type' => self::getAttributeArgType($type, $array, $required),
|
||||||
$key = $attr->getAttribute('key');
|
'resolve' => function ($object, $args, $context, $info) use ($key) {
|
||||||
$type = $attr->getAttribute('type');
|
return $object->getAttribute($key);
|
||||||
$array = $attr->getAttribute('array');
|
|
||||||
$required = $attr->getAttribute('required');
|
|
||||||
$escapedKey = str_replace('$', '_', $key);
|
|
||||||
$collections[$collectionId][$escapedKey] = [
|
|
||||||
'type' => self::getAttributeArgType($type, $array, $required),
|
|
||||||
'resolve' => function ($object, $args, $context, $info) use ($key) {
|
|
||||||
return $object->getAttribute($key);
|
|
||||||
}
|
|
||||||
];
|
|
||||||
$nested->done();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
$nested->wait();
|
];
|
||||||
|
|
||||||
foreach ($collections as $collectionId => $attributes) {
|
|
||||||
go(function () use ($collectionId, $attributes, &$mutationFields, &$queryFields, &$collections, $register, $limit, &$offset, $dbForProject, $wg) {
|
|
||||||
$wg->add();
|
|
||||||
|
|
||||||
$objectType = new ObjectType([
|
|
||||||
'name' => $collectionId,
|
|
||||||
'fields' => $attributes
|
|
||||||
]);
|
|
||||||
$idArgs = [
|
|
||||||
'id' => [
|
|
||||||
'type' => Type::string()
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$listArgs = [
|
|
||||||
'limit' => [
|
|
||||||
'type' => Type::int(),
|
|
||||||
'defaultValue' => $limit,
|
|
||||||
],
|
|
||||||
'offset' => [
|
|
||||||
'type' => Type::int(),
|
|
||||||
'defaultValue' => 0,
|
|
||||||
],
|
|
||||||
'cursor' => [
|
|
||||||
'type' => Type::string(),
|
|
||||||
'defaultValue' => null,
|
|
||||||
],
|
|
||||||
'orderAttributes' => [
|
|
||||||
'type' => Type::listOf(Type::string()),
|
|
||||||
'defaultValue' => [],
|
|
||||||
],
|
|
||||||
'orderType' => [
|
|
||||||
'type' => Type::listOf(Type::string()),
|
|
||||||
'defaultValue' => [],
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$queryFields[$collectionId . 'Get'] = [
|
|
||||||
'type' => $objectType,
|
|
||||||
'args' => $idArgs,
|
|
||||||
'resolve' => self::queryGet($collectionId, $dbForProject)
|
|
||||||
];
|
|
||||||
$queryFields[$collectionId . 'List'] = [
|
|
||||||
'type' => $objectType,
|
|
||||||
'args' => $listArgs,
|
|
||||||
'resolve' => self::queryList($collectionId, $dbForProject)
|
|
||||||
];
|
|
||||||
$mutationFields[$collectionId . 'Create'] = [
|
|
||||||
'type' => $objectType,
|
|
||||||
'args' => $attributes,
|
|
||||||
'resolve' => self::mutateCreate($collectionId, $dbForProject)
|
|
||||||
];
|
|
||||||
$mutationFields[$collectionId . 'Update'] = [
|
|
||||||
'type' => $objectType,
|
|
||||||
'args' => $attributes,
|
|
||||||
'resolve' => self::mutateUpdate($collectionId, $dbForProject)
|
|
||||||
];
|
|
||||||
$mutationFields[$collectionId . 'Delete'] = [
|
|
||||||
'type' => $objectType,
|
|
||||||
'args' => $idArgs,
|
|
||||||
'resolve' => self::mutateDelete($collectionId, $dbForProject)
|
|
||||||
];
|
|
||||||
$wg->done();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$wg->done();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
$wg->wait();
|
foreach ($collections as $collectionId => $attributes) {
|
||||||
|
$objectType = new ObjectType([
|
||||||
|
'name' => $collectionId,
|
||||||
|
'fields' => $attributes
|
||||||
|
]);
|
||||||
|
$idArgs = [
|
||||||
|
'id' => [
|
||||||
|
'type' => Type::string()
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$listArgs = [
|
||||||
|
'limit' => [
|
||||||
|
'type' => Type::int(),
|
||||||
|
'defaultValue' => $limit,
|
||||||
|
],
|
||||||
|
'offset' => [
|
||||||
|
'type' => Type::int(),
|
||||||
|
'defaultValue' => 0,
|
||||||
|
],
|
||||||
|
'cursor' => [
|
||||||
|
'type' => Type::string(),
|
||||||
|
'defaultValue' => null,
|
||||||
|
],
|
||||||
|
'orderAttributes' => [
|
||||||
|
'type' => Type::listOf(Type::string()),
|
||||||
|
'defaultValue' => [],
|
||||||
|
],
|
||||||
|
'orderType' => [
|
||||||
|
'type' => Type::listOf(Type::string()),
|
||||||
|
'defaultValue' => [],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$queryFields[$collectionId . 'Get'] = [
|
||||||
|
'type' => $objectType,
|
||||||
|
'args' => $idArgs,
|
||||||
|
'resolve' => self::queryGet($collectionId, $dbForProject)
|
||||||
|
];
|
||||||
|
$queryFields[$collectionId . 'List'] = [
|
||||||
|
'type' => $objectType,
|
||||||
|
'args' => $listArgs,
|
||||||
|
'resolve' => self::queryList($collectionId, $dbForProject)
|
||||||
|
];
|
||||||
|
$mutationFields[$collectionId . 'Create'] = [
|
||||||
|
'type' => $objectType,
|
||||||
|
'args' => $attributes,
|
||||||
|
'resolve' => self::mutateCreate($collectionId, $dbForProject)
|
||||||
|
];
|
||||||
|
$mutationFields[$collectionId . 'Update'] = [
|
||||||
|
'type' => $objectType,
|
||||||
|
'args' => $attributes,
|
||||||
|
'resolve' => self::mutateUpdate($collectionId, $dbForProject)
|
||||||
|
];
|
||||||
|
$mutationFields[$collectionId . 'Delete'] = [
|
||||||
|
'type' => $objectType,
|
||||||
|
'args' => $idArgs,
|
||||||
|
'resolve' => self::mutateDelete($collectionId, $dbForProject)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset += $limit;
|
||||||
|
}
|
||||||
|
|
||||||
$time_elapsed_secs = (microtime(true) - $start) * 1000;
|
$time_elapsed_secs = (microtime(true) - $start) * 1000;
|
||||||
Console::info("Built GraphQL Project Collection Schema in ${time_elapsed_secs}ms");
|
Console::info("Built GraphQL Project Collection Schema in ${time_elapsed_secs}ms");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue