fix: fix Create Quote Bruno pre-request script#3883
fix: fix Create Quote Bruno pre-request script#3883Onyx2406 wants to merge 1 commit intointerledger:mainfrom
Conversation
The pre-request script for Create Quote tried to retrieve a stored
request object from environment variables via getEnvVar, but Bruno
environment variables are serialized as strings, so the object's
properties (.body.query, .url) were undefined at runtime.
Fix by inlining the CreateWalletAddress GraphQL mutation directly
in the pre-request script and using the RafikiGraphqlHost env var
for the URL.
Also remove the unnecessary `setEnvVar('initialWalletAddressRequest',
req)` from Create Wallet Address since the request object cannot be
properly serialized to env vars.
Closes interledger#3573
❌ Deploy Preview for brilliant-pasca-3e80ec failed. Why did it fail? →
|
There was a problem hiding this comment.
Pull request overview
Fixes the broken Bruno “Create Quote” pre-request script by removing reliance on a serialized req object stored in env vars, and instead constructing a fresh CreateWalletAddress GraphQL request using the configured GraphQL host.
Changes:
- Removed
bru.setEnvVar('initialWalletAddressRequest', req)from “Create Wallet Address” post-response script (non-functional due to env var string serialization). - Updated “Create Quote” pre-request script to inline the CreateWalletAddress mutation and call
{{RafikiGraphqlHost}}/graphqldirectly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| bruno/collections/Rafiki/Rafiki Admin APIs/Create Wallet Address.bru | Removes storing the Bruno req object into env vars after response. |
| bruno/collections/Rafiki/Rafiki Admin APIs/Create Quote.bru | Inlines wallet address creation mutation and uses RafikiGraphqlHost for the manual pre-request call. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -65,7 +65,6 @@ script:post-response { | |||
| if (body?.data) { | |||
| bru.setEnvVar("walletAddressId", body.data.createWalletAddress.walletAddress.id); | |||
| bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.url); | |||
There was a problem hiding this comment.
walletAddressUrl is being set from body.data.createWalletAddress.walletAddress.url, but the GraphQL selection set for walletAddress in this request does not include a url field (it includes address instead). In GraphQL, omitted fields won’t be present in the response, so this will be undefined and the included tests will fail. Align the selection set and the post-response mapping (either request url explicitly if it exists in the schema, or set walletAddressUrl from the selected address field / rename the env var accordingly).
| bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.url); | |
| bru.setEnvVar("walletAddressUrl", body.data.createWalletAddress.walletAddress.address); |
| variables: { | ||
| input: { | ||
| assetId: bru.getEnvVar("assetId"), | ||
| url: "https://" + bru.getEnvVar("OpenPaymentsHost") + "/simon/" + randomInt, |
There was a problem hiding this comment.
The pre-request script builds the wallet address URL using bru.getEnvVar("OpenPaymentsHost"), but this env var isn’t defined anywhere in the repository’s Rafiki Bruno environments (only senderOpenPaymentsHost / receiverOpenPaymentsHost patterns are used elsewhere). This likely produces https://undefined/... URLs by default. Consider switching to an existing env var that is actually set in the collection flow (e.g., the sender Open Payments host) or adding OpenPaymentsHost to the committed environment templates/docs so the request is reproducible.
| url: "https://" + bru.getEnvVar("OpenPaymentsHost") + "/simon/" + randomInt, | |
| url: "https://" + bru.getEnvVar("senderOpenPaymentsHost") + "/simon/" + randomInt, |
| const graphqlUrl = bru.getEnvVar("RafikiGraphqlHost") + "/graphql"; | ||
| const response = await fetch(graphqlUrl, postRequest); | ||
| const body = await response.json(); | ||
| bru.setEnvVar("secondWalletAddressId", body.data.createWalletAddress.walletAddress.id); |
There was a problem hiding this comment.
The script assumes the wallet-address creation succeeded and immediately dereferences body.data.createWalletAddress.walletAddress.id. If the fetch fails (non-2xx) or the GraphQL response contains errors (no data), this will throw a TypeError and obscure the real failure. Add a check for response.ok and/or body?.data?.createWalletAddress (and surface body.errors in the thrown error) before setting secondWalletAddressId.
Summary
Fixes the broken "Create Quote" pre-request script in the Bruno API collection.
Root cause: The
Create Wallet Addresspost-response script stored the Brunoreqobject as an environment variable viabru.setEnvVar('initialWalletAddressRequest', req). However, Bruno environment variables are serialized as strings, so whenCreate Quoteretrieved it withbru.getEnvVar("initialWalletAddressRequest"), the object's properties (.body.query,.url) wereundefined, causing the script to fail.Fix:
CreateWalletAddressGraphQL mutation directly in the Create Quote pre-request scriptbru.getEnvVar("RafikiGraphqlHost")for the URL instead of the stored request objectsetEnvVar('initialWalletAddressRequest', req)from Create Wallet AddressChanges
bruno/.../Create Quote.brubruno/.../Create Wallet Address.brusetEnvVarfor request objectCloses #3573