Skip to content

Commit 3bb4bc7

Browse files
authored
Merge pull request #8399 from Shopify/eon/subscription-migrations
Add app subscription migration commands
2 parents 3f5adc9 + 3b17e4b commit 3bb4bc7

44 files changed

Lines changed: 4560 additions & 4 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@shopify/theme-check-node": "3.29.0",
6565
"@shopify/toml-patch": "0.3.0",
6666
"chokidar": "3.6.0",
67+
"csv-parse": "7.0.2",
6768
"diff": "5.2.2",
6869
"esbuild": "0.28.1",
6970
"graphql-request": "6.1.0",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {gql} from 'graphql-request'
2+
3+
// 250 matches the maximum migration submission batch size; operation results are currently bounded by that contract.
4+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
5+
export const AppSubscriptionMigrationOperationCreateMutation = gql`
6+
mutation AppSubscriptionMigrationOperationCreate($input: AppSubscriptionMigrationOperationCreateInput!) {
7+
appSubscriptionMigrationOperationCreate(input: $input) {
8+
operation {
9+
id
10+
status
11+
total
12+
results(first: 250) {
13+
edges {
14+
node {
15+
shopId
16+
code
17+
}
18+
}
19+
}
20+
}
21+
userErrors {
22+
message
23+
field
24+
}
25+
}
26+
}
27+
`
28+
29+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
30+
export const AppSubscriptionMigrationOperationQuery = gql`
31+
query AppSubscriptionMigrationOperation($apiKey: String!, $id: ID!) {
32+
appSubscriptionMigrationOperation(apiKey: $apiKey, id: $id) {
33+
id
34+
status
35+
total
36+
results(first: 250) {
37+
edges {
38+
node {
39+
shopId
40+
code
41+
}
42+
}
43+
}
44+
}
45+
}
46+
`
47+
48+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
49+
export const AppSubscriptionMigrationOperationCancelMutation = gql`
50+
mutation AppSubscriptionMigrationOperationCancel($input: AppSubscriptionMigrationOperationCancelInput!) {
51+
appSubscriptionMigrationOperationCancel(input: $input) {
52+
operation {
53+
id
54+
status
55+
total
56+
results(first: 250) {
57+
edges {
58+
node {
59+
shopId
60+
code
61+
}
62+
}
63+
}
64+
}
65+
userErrors {
66+
message
67+
field
68+
}
69+
}
70+
}
71+
`
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {operationFlags} from './flags.js'
2+
import {presentMigrationCancellationResult} from './result-presenter.js'
3+
import {linkedAppContext} from '../../../services/app-context.js'
4+
import {cancelMigrationOperations} from '../../../services/subscription-migrations/cancel-operations.js'
5+
import AppLinkedCommand, {AppLinkedCommandOutput} from '../../../utilities/app-linked-command.js'
6+
7+
export default class Cancel extends AppLinkedCommand {
8+
static hidden = true
9+
static summary = 'Cancels app subscription migration operations.'
10+
11+
static descriptionWithMarkdown = `Cancels app subscription migration operations.
12+
13+
Canceling stops additional unprocessed shops, but does not undo shops that have already been scheduled or migrated. Use \`unschedule\` for reversible schedules.
14+
15+
Repeat \`--id\` to cancel every operation GID returned by a multi-batch submission. Use \`--json\` to output the resulting operation states and per-shop results as structured JSON.
16+
17+
Run the command from an app project. By default, it uses the Client ID from the active app configuration. Use \`--path\` to select an app directory or \`--config\` to select a configuration. Pass \`--client-id\` to select a different app within the project. Use \`--reset\` to relink the app.`
18+
19+
static description = this.descriptionWithoutMarkdown()
20+
21+
static examples = [
22+
'<%= config.bin %> <%= command.id %> --id <operation-id>',
23+
'<%= config.bin %> <%= command.id %> --path ../my-app --config staging --id <operation-id-1> --id <operation-id-2>',
24+
'<%= config.bin %> <%= command.id %> --client-id <client-id> --id <operation-id> --json',
25+
]
26+
27+
static flags = {...operationFlags}
28+
29+
async run(): Promise<AppLinkedCommandOutput> {
30+
const {flags} = await this.parse(Cancel)
31+
const {app, remoteApp} = await linkedAppContext({
32+
directory: flags.path,
33+
clientId: flags['client-id'],
34+
forceRelink: flags.reset,
35+
userProvidedConfigName: flags.config,
36+
})
37+
const result = await cancelMigrationOperations({
38+
clientId: remoteApp.apiKey,
39+
operationIds: flags.id,
40+
})
41+
const exitCode = presentMigrationCancellationResult(result, {json: flags.json})
42+
if (exitCode !== 0) process.exitCode = exitCode
43+
return {app}
44+
}
45+
}

0 commit comments

Comments
 (0)