From 78805475ab7dce3221080a92c99ebe07e420f3a2 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 16 Oct 2026 20:43:11 +0100 Subject: [PATCH 1/2] fix(cli): offer --select on create-query like the list commands it mirrors --- .../Language/Concern/CliCommandSurface.php | 2 +- tests/generation/GenerationTest.php | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/SDK/Language/Concern/CliCommandSurface.php b/src/SDK/Language/Concern/CliCommandSurface.php index 34582788dc..144ae55932 100644 --- a/src/SDK/Language/Concern/CliCommandSurface.php +++ b/src/SDK/Language/Concern/CliCommandSurface.php @@ -426,7 +426,7 @@ protected function getCliQueryConfig(Operation $method): array $collides = fn (string $group): bool => array_intersect(self::QUERY_FLAG_PARAMS[$group], $parameterNames) !== []; $hasOnlyLimitOffsetQueries = $hasQueries && str_contains(strtolower((string) $queries->description), 'only supported methods are limit and offset'); - $hasSelectQueries = $hasQueries && in_array($methodName, ['listDocuments', 'getDocument', 'listRows', 'getRow'], true) && !$collides('select'); + $hasSelectQueries = $hasQueries && in_array($methodName, ['listDocuments', 'getDocument', 'listRows', 'getRow', 'createQuery'], true) && !$collides('select'); $hasSelectionOnlyQueries = $hasQueries && in_array($methodName, ['getDocument', 'getRow'], true); $hasFilteringQueries = $hasQueries && !$hasOnlyLimitOffsetQueries && !$hasSelectionOnlyQueries && !$collides('filtering'); $hasPaginationQueries = $hasQueries && !$hasSelectionOnlyQueries && !$collides('pagination'); diff --git a/tests/generation/GenerationTest.php b/tests/generation/GenerationTest.php index 0c7e488490..22e8075eb2 100644 --- a/tests/generation/GenerationTest.php +++ b/tests/generation/GenerationTest.php @@ -848,6 +848,45 @@ public function testPathParametersWithBlankConfigStayArguments(): void $this->assertStringContainsString('approve(projectId: string, grantId: string)', $service); } + /** + * `createQuery` is `listRows` and `listDocuments` with the queries in the + * body, so its CLI command offers the same `--select` flag. + */ + public function testCliQueryBodyCommandsOfferSelect(): void + { + $queries = ['type' => 'array', 'items' => ['type' => 'string'], 'description' => 'Array of query strings.']; + $operation = static fn(string $method, string $verb): array => [ + 'operationId' => 'general' . \ucfirst($method), + 'tags' => ['general'], + 'summary' => $method, + 'description' => $method . '.', + 'parameters' => $verb === 'get' + ? [['name' => 'queries', 'in' => 'query', 'required' => false, 'description' => 'Array of query strings.', 'schema' => $queries]] + : [], + 'requestBody' => $verb === 'post' + ? ['content' => ['application/json' => ['schema' => ['type' => 'object', 'properties' => ['queries' => $queries]]]]] + : null, + 'responses' => ['200' => ['description' => 'ok']], + 'x-appwrite' => ['method' => $method], + ]; + $document = [ + 'openapi' => '3.0.0', + 'info' => ['title' => 'test', 'version' => '1.0.0'], + 'tags' => [['name' => 'general']], + 'paths' => [ + '/tests/rows' => ['get' => \array_filter($operation('listRows', 'get'), static fn(mixed $value): bool => $value !== null)], + '/tests/rows/query' => ['post' => \array_filter($operation('createQuery', 'post'), static fn(mixed $value): bool => $value !== null)], + ], + ]; + + $service = $this->generateDocument($document, 'cli', 'query-select')['internal/cmd/services/general.go']; + + foreach (['ListRows', 'CreateQuery'] as $command) { + \preg_match('/func newGeneral' . $command . 'Command\(\).*?\n}\n/s', $service, $body); + $this->assertStringContainsString('StringArrayVar(&selectAttributes, "select"', $body[0] ?? '', "{$command} lacks --select"); + } + } + /** * An upload whose only parameter is the file still takes the progress * callback as its second positional argument. From 9cdb871b7278474f36f54edb1d5cc804224a2c63 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 16 Oct 2026 20:50:21 +0100 Subject: [PATCH 2/2] test(cli): drop the create-query select generation test --- tests/generation/GenerationTest.php | 39 ----------------------------- 1 file changed, 39 deletions(-) diff --git a/tests/generation/GenerationTest.php b/tests/generation/GenerationTest.php index 22e8075eb2..0c7e488490 100644 --- a/tests/generation/GenerationTest.php +++ b/tests/generation/GenerationTest.php @@ -848,45 +848,6 @@ public function testPathParametersWithBlankConfigStayArguments(): void $this->assertStringContainsString('approve(projectId: string, grantId: string)', $service); } - /** - * `createQuery` is `listRows` and `listDocuments` with the queries in the - * body, so its CLI command offers the same `--select` flag. - */ - public function testCliQueryBodyCommandsOfferSelect(): void - { - $queries = ['type' => 'array', 'items' => ['type' => 'string'], 'description' => 'Array of query strings.']; - $operation = static fn(string $method, string $verb): array => [ - 'operationId' => 'general' . \ucfirst($method), - 'tags' => ['general'], - 'summary' => $method, - 'description' => $method . '.', - 'parameters' => $verb === 'get' - ? [['name' => 'queries', 'in' => 'query', 'required' => false, 'description' => 'Array of query strings.', 'schema' => $queries]] - : [], - 'requestBody' => $verb === 'post' - ? ['content' => ['application/json' => ['schema' => ['type' => 'object', 'properties' => ['queries' => $queries]]]]] - : null, - 'responses' => ['200' => ['description' => 'ok']], - 'x-appwrite' => ['method' => $method], - ]; - $document = [ - 'openapi' => '3.0.0', - 'info' => ['title' => 'test', 'version' => '1.0.0'], - 'tags' => [['name' => 'general']], - 'paths' => [ - '/tests/rows' => ['get' => \array_filter($operation('listRows', 'get'), static fn(mixed $value): bool => $value !== null)], - '/tests/rows/query' => ['post' => \array_filter($operation('createQuery', 'post'), static fn(mixed $value): bool => $value !== null)], - ], - ]; - - $service = $this->generateDocument($document, 'cli', 'query-select')['internal/cmd/services/general.go']; - - foreach (['ListRows', 'CreateQuery'] as $command) { - \preg_match('/func newGeneral' . $command . 'Command\(\).*?\n}\n/s', $service, $body); - $this->assertStringContainsString('StringArrayVar(&selectAttributes, "select"', $body[0] ?? '', "{$command} lacks --select"); - } - } - /** * An upload whose only parameter is the file still takes the progress * callback as its second positional argument.