Skip to content

Commit 32b0788

Browse files
authored
Merge pull request #6233 from Shopify/08-08-update_migration_mutations_to_accept_registration_id_or_registration_uuid_based_on_which_client_we_are_using
Update migration mutations to accept registration id or registration uuid based on which client we are using
2 parents 48ae8ed + 13f8fa7 commit 32b0788

11 files changed

+213
-155
lines changed

packages/app/src/cli/api/graphql/extension_migrate_app_module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {gql} from 'graphql-request'
22

3+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
34
export const MigrateAppModuleMutation = gql`
4-
mutation MigrateAppModule($apiKey: String!, $registrationId: ID!, $type: String!) {
5-
migrateAppModule(input: {apiKey: $apiKey, registrationId: $registrationId, type: $type}) {
5+
mutation MigrateAppModule($apiKey: String!, $registrationId: ID, $registrationUuid: String, $type: String!) {
6+
migrateAppModule(
7+
input: {apiKey: $apiKey, registrationId: $registrationId, registrationUuid: $registrationUuid, type: $type}
8+
) {
69
migratedAppModule
710
userErrors {
811
field
@@ -14,7 +17,8 @@ export const MigrateAppModuleMutation = gql`
1417

1518
export interface MigrateAppModuleVariables {
1619
apiKey: string
17-
registrationId: string
20+
registrationId?: string
21+
registrationUuid?: string
1822
type: string
1923
}
2024

packages/app/src/cli/api/graphql/extension_migrate_flow_extension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {gql} from 'graphql-request'
22

3+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
34
export const MigrateFlowExtensionMutation = gql`
4-
mutation MigrateFlowExtension($apiKey: String!, $registrationId: ID!) {
5-
migrateFlowExtension(input: {apiKey: $apiKey, registrationId: $registrationId}) {
5+
mutation MigrateFlowExtension($apiKey: String!, $registrationId: ID, $registrationUuid: String) {
6+
migrateFlowExtension(
7+
input: {apiKey: $apiKey, registrationId: $registrationId, registrationUuid: $registrationUuid}
8+
) {
69
migratedFlowExtension
710
userErrors {
811
field
@@ -14,7 +17,8 @@ export const MigrateFlowExtensionMutation = gql`
1417

1518
export interface MigrateFlowExtensionVariables {
1619
apiKey: string
17-
registrationId: string
20+
registrationId?: string
21+
registrationUuid?: string
1822
}
1923

2024
export interface MigrateFlowExtensionSchema {

packages/app/src/cli/api/graphql/extension_migrate_to_ui_extension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import {gql} from 'graphql-request'
22

3+
// eslint-disable-next-line @shopify/cli/no-inline-graphql
34
export const MigrateToUiExtensionQuery = gql`
4-
mutation MigrateToUiExtension($apiKey: String!, $registrationId: ID!) {
5-
migrateToUiExtension(input: {apiKey: $apiKey, registrationId: $registrationId}) {
5+
mutation MigrateToUiExtension($apiKey: String!, $registrationId: ID, $registrationUuid: String) {
6+
migrateToUiExtension(
7+
input: {apiKey: $apiKey, registrationId: $registrationId, registrationUuid: $registrationUuid}
8+
) {
69
migratedToUiExtension
710
userErrors {
811
field
@@ -14,7 +17,8 @@ export const MigrateToUiExtensionQuery = gql`
1417

1518
export interface MigrateToUiExtensionVariables {
1619
apiKey: string
17-
registrationId: string
20+
registrationId?: string
21+
registrationUuid?: string
1822
}
1923

2024
export interface MigrateToUiExtensionSchema {

packages/app/src/cli/services/context/identifiers-extensions.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,12 @@ describe('ensureExtensionsIds: Migrates extension', () => {
885885
},
886886
})
887887

888-
expect(migrateExtensionsToUIExtension).toBeCalledWith(
888+
expect(migrateExtensionsToUIExtension).toBeCalledWith({
889889
extensionsToMigrate,
890-
opts.appId,
890+
appId: opts.appId,
891891
remoteExtensions,
892-
expect.any(PartnersClient),
893-
)
892+
migrationClient: expect.any(PartnersClient),
893+
})
894894
})
895895
})
896896

packages/app/src/cli/services/context/identifiers-extensions.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,87 +61,87 @@ export async function ensureExtensionsIds(
6161

6262
// Migration is only supported in partners client
6363
const clientName = options.developerPlatformClient.clientName
64-
const migrationsClient = clientName === ClientName.Partners ? options.developerPlatformClient : new PartnersClient()
64+
const migrationClient = clientName === ClientName.Partners ? options.developerPlatformClient : new PartnersClient()
6565

6666
let didMigrateDashboardExtensions = false
6767

6868
if (uiExtensionsToMigrate.length > 0) {
6969
const confirmedMigration = await extensionMigrationPrompt(uiExtensionsToMigrate)
7070
if (!confirmedMigration) throw new AbortSilentError()
71-
remoteExtensions = await migrateExtensionsToUIExtension(
72-
uiExtensionsToMigrate,
73-
options.appId,
71+
remoteExtensions = await migrateExtensionsToUIExtension({
72+
extensionsToMigrate: uiExtensionsToMigrate,
73+
appId: options.appId,
7474
remoteExtensions,
75-
migrationsClient,
76-
)
75+
migrationClient,
76+
})
7777
didMigrateDashboardExtensions = true
7878
}
7979

8080
if (flowExtensionsToMigrate.length > 0) {
8181
const confirmedMigration = await extensionMigrationPrompt(flowExtensionsToMigrate, false)
8282
if (!confirmedMigration) throw new AbortSilentError()
83-
const newRemoteExtensions = await migrateFlowExtensions(
84-
flowExtensionsToMigrate,
85-
options.appId,
86-
dashboardExtensions,
87-
migrationsClient,
88-
)
83+
const newRemoteExtensions = await migrateFlowExtensions({
84+
extensionsToMigrate: flowExtensionsToMigrate,
85+
appId: options.appId,
86+
remoteExtensions: dashboardExtensions,
87+
migrationClient,
88+
})
8989
remoteExtensions = remoteExtensions.concat(newRemoteExtensions)
9090
didMigrateDashboardExtensions = true
9191
}
9292

9393
if (marketingToMigrate.length > 0) {
9494
const confirmedMigration = await extensionMigrationPrompt(marketingToMigrate, false)
9595
if (!confirmedMigration) throw new AbortSilentError()
96-
const newRemoteExtensions = await migrateAppModules(
97-
marketingToMigrate,
98-
options.appId,
99-
'marketing_activity',
100-
dashboardExtensions,
101-
migrationsClient,
102-
)
96+
const newRemoteExtensions = await migrateAppModules({
97+
extensionsToMigrate: marketingToMigrate,
98+
appId: options.appId,
99+
type: 'marketing_activity',
100+
remoteExtensions: dashboardExtensions,
101+
migrationClient,
102+
})
103103
remoteExtensions = remoteExtensions.concat(newRemoteExtensions)
104104
didMigrateDashboardExtensions = true
105105
}
106106

107107
if (paymentsToMigrate.length > 0) {
108108
const confirmedMigration = await extensionMigrationPrompt(paymentsToMigrate, false)
109109
if (!confirmedMigration) throw new AbortSilentError()
110-
const newRemoteExtensions = await migrateAppModules(
111-
paymentsToMigrate,
112-
options.appId,
113-
'payments_extension',
114-
dashboardExtensions,
115-
migrationsClient,
116-
)
110+
const newRemoteExtensions = await migrateAppModules({
111+
extensionsToMigrate: paymentsToMigrate,
112+
appId: options.appId,
113+
type: 'payments_extension',
114+
remoteExtensions: dashboardExtensions,
115+
migrationClient,
116+
})
117117
remoteExtensions = remoteExtensions.concat(newRemoteExtensions)
118118
didMigrateDashboardExtensions = true
119119
}
120120

121121
if (subscriptionLinksToMigrate.length > 0) {
122122
const confirmedMigration = await extensionMigrationPrompt(subscriptionLinksToMigrate, false)
123123
if (!confirmedMigration) throw new AbortSilentError()
124-
const newRemoteExtensions = await migrateAppModules(
125-
subscriptionLinksToMigrate,
126-
options.appId,
127-
'subscription_link_extension',
128-
dashboardExtensions,
129-
migrationsClient,
130-
)
124+
const newRemoteExtensions = await migrateAppModules({
125+
extensionsToMigrate: subscriptionLinksToMigrate,
126+
appId: options.appId,
127+
type: 'subscription_link_extension',
128+
remoteExtensions: dashboardExtensions,
129+
migrationClient,
130+
})
131131
remoteExtensions = remoteExtensions.concat(newRemoteExtensions)
132132
didMigrateDashboardExtensions = true
133133
}
134134

135135
if (adminLinkExtensionsToMigrate.length > 0) {
136136
const confirmedMigration = await extensionMigrationPrompt(adminLinkExtensionsToMigrate, false)
137137
if (!confirmedMigration) throw new AbortSilentError()
138-
const newRemoteExtensions = await migrateAppModules(
139-
adminLinkExtensionsToMigrate,
140-
options.appId,
141-
'admin_link',
142-
dashboardExtensions,
143-
migrationsClient,
144-
)
138+
const newRemoteExtensions = await migrateAppModules({
139+
extensionsToMigrate: adminLinkExtensionsToMigrate,
140+
appId: options.appId,
141+
type: 'admin_link',
142+
remoteExtensions: dashboardExtensions,
143+
migrationClient,
144+
})
145145
remoteExtensions = remoteExtensions.concat(newRemoteExtensions)
146146
didMigrateDashboardExtensions = true
147147
}

packages/app/src/cli/services/dev/migrate-app-module.test.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {getModulesToMigrate, migrateAppModules} from './migrate-app-module.js'
22
import {LocalSource, RemoteSource} from '../context/identifiers.js'
33
import {testDeveloperPlatformClient} from '../../models/app/app.test-data.js'
4+
import {ClientName} from '../../utilities/developer-platform-client.js'
45
import {describe, expect, test} from 'vitest'
56

67
function getLocalExtension(attributes: Partial<LocalSource> = {}) {
@@ -140,54 +141,57 @@ describe('getModulesToMigrate()', () => {
140141
})
141142

142143
describe('migrateAppModules()', () => {
143-
test('performs a graphQL mutation for each extension', async () => {
144-
// Given
144+
test('uses registrationUuid for AppManagement client', async () => {
145145
const extensionsToMigrate = [
146-
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id1'})},
147-
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id2'})},
146+
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id1', uuid: 'uuid1'})},
147+
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id2', uuid: 'uuid2'})},
148148
]
149149
const appId = '123abc'
150150
const type = 'payments_extension'
151151
const remoteExtensions = extensionsToMigrate.map(({remote}) => remote)
152-
const developerPlatformClient = testDeveloperPlatformClient()
152+
const appManagementClient = testDeveloperPlatformClient({clientName: ClientName.AppManagement})
153+
const migrationClient = testDeveloperPlatformClient()
153154

154-
// When
155-
await migrateAppModules(extensionsToMigrate, appId, type, remoteExtensions, developerPlatformClient)
155+
await migrateAppModules({
156+
extensionsToMigrate,
157+
appId,
158+
type,
159+
remoteExtensions,
160+
migrationClient,
161+
})
156162

157-
// Then
158-
expect(developerPlatformClient.migrateAppModule).toHaveBeenCalledTimes(extensionsToMigrate.length)
159-
expect(developerPlatformClient.migrateAppModule).toHaveBeenCalledWith({
163+
expect(migrationClient.migrateAppModule).toHaveBeenCalledTimes(extensionsToMigrate.length)
164+
expect(migrationClient.migrateAppModule).toHaveBeenCalledWith({
160165
apiKey: appId,
161-
registrationId: extensionsToMigrate[0]!.remote.id,
166+
registrationId: undefined,
167+
registrationUuid: extensionsToMigrate[0]!.remote.uuid,
162168
type,
163169
})
164-
expect(developerPlatformClient.migrateAppModule).toHaveBeenCalledWith({
170+
expect(migrationClient.migrateAppModule).toHaveBeenCalledWith({
165171
apiKey: appId,
166-
registrationId: extensionsToMigrate[1]!.remote.id,
172+
registrationId: undefined,
173+
registrationUuid: extensionsToMigrate[1]!.remote.uuid,
167174
type,
168175
})
169176
})
170177

171178
test('Returns updated remoteExensions', async () => {
172-
// Given
173179
const extensionsToMigrate = [
174-
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id1'})},
175-
{local: getLocalExtension(), remote: getRemoteExtension({id: 'id2'})},
180+
{local: getLocalExtension(), remote: getRemoteExtension()},
181+
{local: getLocalExtension(), remote: getRemoteExtension()},
176182
]
177183
const appId = '123abc'
178184
const type = 'payments_extension'
179185
const remoteExtensions = extensionsToMigrate.map(({remote}) => remote)
180186

181-
// When
182-
const result = await migrateAppModules(
187+
const result = await migrateAppModules({
183188
extensionsToMigrate,
184189
appId,
185190
type,
186191
remoteExtensions,
187-
testDeveloperPlatformClient(),
188-
)
192+
migrationClient: testDeveloperPlatformClient(),
193+
})
189194

190-
// Then
191195
expect(result).toStrictEqual(remoteExtensions.map((remote) => ({...remote, type: 'PAYMENTS_EXTENSION'})))
192196
})
193197
})

packages/app/src/cli/services/dev/migrate-app-module.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,25 @@ export function getModulesToMigrate(
8888
}, [])
8989
}
9090

91-
export async function migrateAppModules(
92-
extensionsToMigrate: LocalRemoteSource[],
93-
appId: string,
94-
type: string,
95-
remoteExtensions: RemoteSource[],
96-
developerPlatformClient: DeveloperPlatformClient,
97-
) {
91+
export async function migrateAppModules(options: {
92+
extensionsToMigrate: LocalRemoteSource[]
93+
appId: string
94+
type: string
95+
remoteExtensions: RemoteSource[]
96+
migrationClient: DeveloperPlatformClient
97+
}) {
98+
const {extensionsToMigrate, appId, type, remoteExtensions, migrationClient} = options
99+
98100
const migratedIDs = await Promise.all(
99-
extensionsToMigrate.map(({remote}) => migrateAppModule(appId, remote.id, type, developerPlatformClient)),
101+
extensionsToMigrate.map(({remote}) =>
102+
migrateAppModule({
103+
apiKey: appId,
104+
registrationId: undefined,
105+
registrationUuid: remote.uuid,
106+
type,
107+
migrationClient,
108+
}),
109+
),
100110
)
101111

102112
return remoteExtensions
@@ -109,19 +119,23 @@ export async function migrateAppModules(
109119
})
110120
}
111121

112-
async function migrateAppModule(
113-
apiKey: MigrateAppModuleVariables['apiKey'],
114-
registrationId: MigrateAppModuleVariables['registrationId'],
115-
type: MigrateAppModuleVariables['type'],
116-
developerPlatformClient: DeveloperPlatformClient,
117-
) {
122+
async function migrateAppModule(options: {
123+
apiKey: MigrateAppModuleVariables['apiKey']
124+
registrationId: MigrateAppModuleVariables['registrationId']
125+
registrationUuid: MigrateAppModuleVariables['registrationUuid']
126+
type: MigrateAppModuleVariables['type']
127+
migrationClient: DeveloperPlatformClient
128+
}) {
129+
const {apiKey, registrationId, registrationUuid, type, migrationClient} = options
130+
118131
const variables: MigrateAppModuleVariables = {
119132
apiKey,
120133
registrationId,
134+
registrationUuid,
121135
type,
122136
}
123137

124-
const result: MigrateAppModuleSchema = await developerPlatformClient.migrateAppModule(variables)
138+
const result: MigrateAppModuleSchema = await migrationClient.migrateAppModule(variables)
125139

126140
if (result?.migrateAppModule?.userErrors?.length > 0) {
127141
const errors = result.migrateAppModule.userErrors.map((error) => error.message).join(', ')

0 commit comments

Comments
 (0)