Skip to content

Conversation

@ericlee878
Copy link
Contributor

@ericlee878 ericlee878 commented Nov 11, 2025

Resolves: https://github.com/orgs/shop/projects/208/views/34?pane=issue&itemId=137773625&issue=shop%7Cissues-api-foundations%7C1069

Background
The basic setup of the BulkOps CLI command was done here. The basic command used BulkOps Query. We are implementing BulkOps Mutation in this PR.

Implementation Details

  • We parse the query given to us in the flag to determine if the GraphQL command is a query or a mutation. Then, we do the respective GraphQL API call.

  • Bulk operation CLI accept variables via the --variables flag in JSON format. However, the Shopify Admin API requires these variables to be uploaded as a JSONL file rather than passed inline. So, in the stage-file.ts file, we needed to:

      1. Create a staged upload target via `stagedUploadsCreate` mutation.
      2. Extract the variables from JSON format and put it in a JSONL file. 
      3. Upload the JSONL file to the temporary GCS URL from staged upload.
      4. Pass the staged upload key to `bulkOperationRunMutation`.
    
  • There will be a future PR that deals with creating a --variable-file flag that links to a file containing the values for bulk mutations, in JSONL format.

  • Used GraphQL code generation configuration for the bulkOperationRunMutation API and stagedUpload API. Ran pnpm graphql-codegen to generate TypeScript types from GraphQL queries/mutations

Architecture improvements:

  • Authentication happens once at executeBulkOperation level via ensureAuthenticatedAdmin, then the session is passed down to runBulkOperationQuery and runBulkOperationMutation
  • Command flags are spread directly into executeBulkOperation (...flags) instead of parsing individual properties.

Testing

  • Setup
    1. Follow the instructions here to setup a test app
    2. Go here and create a store (if not already have one).
  • Testing Mutation
    To test the mutation part of the CLI, run:
pnpm shopify app execute --path=<path to test app> --query='mutation productUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id tags } userErrors { field message } } }' --variables='[{"input": {"id": "gid://shopify/Product/<product id>", "tags": ["bulk-test"]}}]'

@ericlee878 ericlee878 changed the title implement mutation support for BulkOps CLI command Implement mutation support for BulkOps CLI command Nov 11, 2025
Copy link
Contributor Author

ericlee878 commented Nov 11, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
79.23% (+0.01% 🔼)
13636/17210
🟡 Branches
73.1% (-0.01% 🔻)
6648/9095
🟡 Functions
79.39% (+0.02% 🔼)
3517/4430
🟡 Lines
79.58% (+0% 🔼)
12879/16183
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / bulk-operation-run-mutation.ts
100% 100% 100% 100%
🟢
... / bulk-operation-run-query.ts
100% 100% 100% 100%
🟢
... / staged-uploads-create.ts
100% 100% 100% 100%
🟢
... / execute-bulk-operation.ts
100% 90% 100% 100%
🟢
... / run-mutation.ts
100% 100% 100% 100%
🟢
... / run-query.ts
100% 100% 100% 100%
🟡
... / stage-file.ts
74.29% 53.33% 85.71% 73.53%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / ConcurrentOutput.tsx
98.36% (-1.64% 🔻)
92% (-4% 🔻)
100%
98.33% (-1.67% 🔻)

Test suite run success

3367 tests passing in 1380 suites.

Report generated by 🧪jest coverage report action from aad7af4

@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch 3 times, most recently from 8d8577c to bfcac3b Compare November 12, 2025 22:40
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch from c658f01 to 8b95f00 Compare November 12, 2025 22:40
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from bfcac3b to 94bc2e2 Compare November 12, 2025 22:46
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch from 8b95f00 to 7dc25cf Compare November 12, 2025 22:46
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 94bc2e2 to ed2bd19 Compare November 12, 2025 22:49
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch 2 times, most recently from 2ef312a to f813e73 Compare November 12, 2025 23:04
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch 2 times, most recently from 4e07e3b to 65f1d93 Compare November 12, 2025 23:18
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch from f813e73 to 0e625de Compare November 12, 2025 23:18
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 65f1d93 to 8f6a1f5 Compare November 13, 2025 00:29
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch from 0e625de to 4024e20 Compare November 13, 2025 00:29
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 8f6a1f5 to a6cdaba Compare November 13, 2025 00:58
@ericlee878 ericlee878 force-pushed the 11-07-implement_simple_bulk_query branch 2 times, most recently from a6645ff to 3784bae Compare November 13, 2025 01:09
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from a6cdaba to ac6e796 Compare November 13, 2025 01:09
@jordanverasamy jordanverasamy changed the base branch from 11-07-implement_simple_bulk_query to graphite-base/6596 November 13, 2025 18:19
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from ac6e796 to 85c5abb Compare November 14, 2025 00:26
@ericlee878 ericlee878 marked this pull request as ready for review November 14, 2025 00:27
@ericlee878 ericlee878 requested a review from a team as a code owner November 14, 2025 00:27
@github-actions
Copy link
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 85c5abb to 2cd36fd Compare November 14, 2025 00:54
@ericlee878 ericlee878 requested a review from a team as a code owner November 14, 2025 00:54
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch 2 times, most recently from d8db357 to 3a4833e Compare November 17, 2025 23:54
Copy link
Contributor

@jordanverasamy jordanverasamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another pass! Looking really good. I like the changes to stageFile, thanks for being patient with me on those :)

@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 3a4833e to 3040057 Compare November 18, 2025 02:41
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch 3 times, most recently from 9cfc66c to b07001c Compare November 18, 2025 22:27
Copy link
Contributor

@jordanverasamy jordanverasamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work. I 🎩 and things are good. Looking forward to getting this in!

@jordanverasamy
Copy link
Contributor

🎩 :

pnpm shopify app execute \
--path="../my-test-app/my-test-app" \
--query='mutation createProduct($productSet: ProductSetInput!) { productSet(synchronous: true, input: $productSet) { product { id } } }' \
--variables='{ "productSet": { "title": "Winter hat" } }' \
--variables='{ "productSet": { "title": "Winter coat" } }' \
--variables='{ "productSet": { "title": "Winter pants" } }'
image image

Copy link
Contributor Author

Thanks for adding this!

@nickwesselman
Copy link
Contributor

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @nickwesselman! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/[email protected]

Caution

After installing, validate the version by running just shopify in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Copy link
Contributor

@nickwesselman nickwesselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command namespace (shopify app bulk execute) and executing with the app's api key are important before merging this one 👍

Copy link
Contributor

Mentioned elsewhere, but moving to bulk execute is OK as a follow up.

@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from b07001c to 5c60deb Compare November 19, 2025 21:19
@ericlee878 ericlee878 force-pushed the 11-10-implement-bulkops-mutation-to-cli branch from 5c60deb to aad7af4 Compare November 19, 2025 21:23
@ericlee878 ericlee878 closed this Nov 19, 2025
@ericlee878 ericlee878 reopened this Nov 19, 2025
@ericlee878
Copy link
Contributor Author

ericlee878 commented Nov 19, 2025

Mentioned elsewhere, but moving to bulk execute is OK as a follow up.

Follow up ticket

Copy link
Contributor

@nickwesselman nickwesselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with my remaining requests as follow-ups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants