diff --git a/src/Appwrite/GraphQL/Resolvers.php b/src/Appwrite/GraphQL/Resolvers.php index 053e6a2b07..d42183a4f0 100644 --- a/src/Appwrite/GraphQL/Resolvers.php +++ b/src/Appwrite/GraphQL/Resolvers.php @@ -7,6 +7,7 @@ use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use Utopia\App; use Utopia\Database\Database; +use Utopia\Database\ID; use Utopia\Exception; use Utopia\Route; @@ -114,12 +115,7 @@ class Resolvers $swoole->post = [ 'databaseId' => $databaseId, 'collectionId' => $collectionId, - 'limit' => $args['limit'], - 'offset' => $args['offset'], - 'cursor' => $args['cursor'], - 'cursorDirection' => $args['cursorDirection'], - 'orderAttributes' => $args['orderAttributes'], - 'orderType' => $args['orderType'], + 'queries' => $args['queries'], ]; $swoole->server['request_method'] = 'GET'; $swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents"; @@ -154,13 +150,11 @@ class Resolvers $response = $utopia->getResource('response', true); $swoole = $request->getSwoole(); - $id = $args['id'] ?? 'unique()'; - $read = $args['read']; - $write = $args['write']; + $id = $args['id'] ?? ID::unique(); + $permissions = $args['permissions']; unset($args['id']); - unset($args['read']); - unset($args['write']); + unset($args['permissions']); // Order must be the same as the route params $swoole->post = [ @@ -168,8 +162,7 @@ class Resolvers 'documentId' => $id, 'collectionId' => $collectionId, 'data' => $args, - 'read' => $read, - 'write' => $write, + 'permissions' => $permissions, ]; $swoole->server['request_method'] = $method; $swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents"; @@ -256,9 +249,9 @@ class Resolvers return; } - if (\array_key_exists('$id', $payload)) { - $payload['_id'] = $payload['$id']; - } + $payload = \array_map(function ($property) { + return \str_replace('$', '_', $property); + }, $payload); $resolve($payload); } diff --git a/src/Appwrite/GraphQL/SchemaBuilder.php b/src/Appwrite/GraphQL/SchemaBuilder.php index 4cec739b63..989af78f18 100644 --- a/src/Appwrite/GraphQL/SchemaBuilder.php +++ b/src/Appwrite/GraphQL/SchemaBuilder.php @@ -10,6 +10,7 @@ use Swoole\Coroutine\WaitGroup; use Swoole\Http\Response as SwooleResponse; use Utopia\App; use Utopia\Database\Database; +use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Registry\Registry; use Utopia\Route; @@ -124,7 +125,7 @@ class SchemaBuilder foreach ($responseModels as $responseModel) { $type = TypeRegistry::get($responseModel->getType()); $description = $route->getDesc(); - $args = []; + $params = []; foreach ($route->getParams() as $key => $value) { $argType = TypeMapper::typeFromParameter( @@ -133,7 +134,7 @@ class SchemaBuilder !$value['optional'], $value['injections'] ); - $args[$key] = [ + $params[$key] = [ 'type' => $argType, 'description' => $value['description'], 'defaultValue' => $value['default'] @@ -143,7 +144,7 @@ class SchemaBuilder $field = [ 'type' => $type, 'description' => $description, - 'args' => $args, + 'args' => $params, 'resolve' => Resolvers::resolveAPIRequest($utopia, $route) ]; @@ -196,9 +197,11 @@ class SchemaBuilder while ( !empty($attrs = Authorization::skip(fn() => $dbForProject->find( - 'attributes', - limit: $limit, - offset: $offset + collection: 'attributes', + queries: [ + Query::limit($limit), + Query::offset($offset), + ] ))) ) { $wg->add(); @@ -223,10 +226,12 @@ class SchemaBuilder foreach ($collections as $collectionId => $attributes) { $objectType = new ObjectType([ 'name' => $collectionId, - 'fields' => \array_merge( - ["_id" => ['type' => Type::string()]], - $attributes - ), + 'fields' => [ + "_id" => [ + 'type' => Type::string() + ], + ...$attributes + ], ]); $attributes = \array_merge( $attributes, diff --git a/src/Appwrite/GraphQL/TypeRegistry.php b/src/Appwrite/GraphQL/TypeRegistry.php index 99111262c0..6d7721575b 100644 --- a/src/Appwrite/GraphQL/TypeRegistry.php +++ b/src/Appwrite/GraphQL/TypeRegistry.php @@ -44,40 +44,15 @@ class TypeRegistry ], ], 'list' => [ - 'limit' => [ - 'type' => Type::int(), - 'defaultValue' => 25, - ], - 'offset' => [ - 'type' => Type::int(), - 'defaultValue' => 0, - ], - 'cursor' => [ - 'type' => Type::string(), - 'defaultValue' => '', - ], - 'cursorDirection' => [ - 'type' => Type::string(), - 'defaultValue' => Database::CURSOR_AFTER, - ], - 'orderAttributes' => [ + 'queries' => [ 'type' => Type::listOf(Type::string()), - 'defaultValue' => [], - ], - 'orderTypes' => [ - 'type' => Type::listOf(Type::string()), - 'defaultValue' => [], ], ], 'mutate' => [ - 'read' => [ + 'permissions' => [ 'type' => Type::listOf(Type::string()), - 'defaultValue' => ['role:member'], - ], - 'write' => [ - 'type' => Type::listOf(Type::string()), - 'defaultValue' => ['role:member'], - ], + 'defaultValue' => [], + ] ], ];