feat(graphile-test): add withTransaction to pgClient in test context#1087
Open
pyramation wants to merge 1 commit intomainfrom
Open
feat(graphile-test): add withTransaction to pgClient in test context#1087pyramation wants to merge 1 commit intomainfrom
pyramation wants to merge 1 commit intomainfrom
Conversation
In production, @dataplan/pg provides withTransaction on the pgClient. In tests, the raw pg Client lacks it, causing plugins that call pgClient.withTransaction() (e.g. graphile-presigned-url-plugin) to fail unless tests manually monkey-patch the method. This adds a savepoint-based withTransaction implementation to the client inside the withPgClient callback. Savepoints nest cleanly inside the test harness's outer transaction, matching production behavior. Eliminates the need for per-test monkey patches.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Adds a savepoint-based
withTransactionimplementation to thepgClientprovided inside thewithPgClientcallback ingraphile-test's execution context.In production,
@dataplan/pgprovideswithTransactionon the pgClient. In tests, the rawpg.Clientfrompgsql-testlacks this method, causing any Graphile plugin that callspgClient.withTransaction()(e.g.graphile-presigned-url-plugin) to crash at runtime unless each test file manually monkey-patches the method.This fix augments the client lazily (guarded by
typeofcheck) with a savepoint-based implementation that nests cleanly inside the test harness's outer transaction. Downstream tests inconstructive-dbcan now remove their per-file monkey patches.Review & Testing Checklist for Human
withTransactionbehaves correctly when the callback throws (shouldROLLBACK TO SAVEPOINTand re-throw, not leave the transaction in a broken state)pgClient(attachingwithTransactionpermanently) doesn't cause issues across multiplewithPgClientcalls in the same test — theifguard prevents re-assignment but the method stays attachedconstructive-db'sminio-multi-scope-graphql.integration.test.tsand confirm the storage upload tests still passNotes
constructive-db's integration tests. A focused unit test could be added as a follow-up.eslint-disablefor@typescript-eslint/no-explicit-anyis required because the rawpg.Clienttype doesn't declarewithTransaction.Link to Devin session: https://app.devin.ai/sessions/7903d2a3e7a34c6daa605e12d6b80d9e
Requested by: @pyramation