fix(rds): star columns, empty where objects, nullable limit/offset - #279
Merged
Conversation
select() with columns: ['*'] rendered SELECT "*", which PostgreSQL rejects
(column "*" does not exist, 42703). A bare * now stays unquoted, matching
AWS; a qualified persons.* remains quoted ("persons"."*") as AWS does.
An empty where object ({} or {and: []}) emitted a dangling WHERE keyword
(SELECT ... WHERE LIMIT :P0 -> syntax error at or near "LIMIT", 42601) in
SELECT/UPDATE/DELETE; the clause is now omitted when it renders empty.
limit/offset now use nullish checks so 0 is emitted as a parameter, and the
local test harness exposes ctx.args as {} when no arguments are passed,
matching the AppSync runtime.
All new snapshots recorded from AWS AppSync EvaluateCode.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
A customer's AppSync JS resolver calling
select({ table, columns: ['*'], limit, offset })from@aws-appsync/utils/rdsfails in several ways. Root causes in this library:columns: ['*']renderedSELECT "*", which PostgreSQL rejects withcolumn "*" does not exist(SQLState 42703). AWS leaves a bare*unquoted.whereobject ({}or{and: []}) emitted a danglingWHEREkeyword —SELECT ... WHERE LIMIT :P0→syntax error at or near "LIMIT"(SQLState 42601) — in SELECT, UPDATE, and DELETE statements. AWS omits the clause entirely.limit: 0/offset: 0were silently dropped by truthy checks. AWS emits them as parameters.(The remaining customer symptom — a TypeError when the query has no arguments at all — is a
ctx.argsconstruction issue in the AppSync provider, not in this library, and is handled separately.)Changes
rds/index.js:quoteIdentifier(): a bare*stays unquoted. Note AWS does quote a qualified star (persons.*→"persons"."*"), so only the exact string*is special-cased.WHEREkeyword when the built clause is empty.limit/offset: nullish checks (!= null) so0is emitted andnull/omitted is skipped.__tests__/helpers.js: the local harness now exposesctx.argsas{}when the context carries no arguments, matching the AppSync runtime (verified: AWSEvaluateCodenormalizesctx.argseven for an entirely empty context).__tests__/resolvers.test.js: newselect statement edge casesdescribe block (10 tests), including the customer's exact resolver shape. All new snapshots recorded from real AWS AppSyncEvaluateCode.package.json: version bump to 0.1.3.Verification
npm test: 85 passed, 83 snapshots (10 newly AWS-recorded).APPSYNC_JS_LIBS_VERSION=fix-rds-utils: theDatabaseErrorExceptionis gone and the generated statement executes (SELECT * FROM "domain"."color" LIMIT :P0).🤖 Generated with Claude Code