Skip to content

Commit

Permalink
Merge pull request #5213 from Shopify/01-16-fix_dev_when_resetting_an…
Browse files Browse the repository at this point in the history
…d_creating_a_new_app

Fix dev when resetting and creating a new app
  • Loading branch information
isaacroldan authored Jan 17, 2025
2 parents dbd2501 + 2fff7ea commit 58216c7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CreateAppMutationVariables = Types.Exact<{

export type CreateAppMutation = {
appCreate: {
app?: {id: string; key: string} | null
app?: {id: string; key: string; activeRoot: {clientCredentials: {secrets: {key: string}[]}}} | null
userErrors: {category: string; message: string; on: JsonMapType}[]
}
}
Expand Down Expand Up @@ -64,6 +64,37 @@ export const CreateApp = {
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
{kind: 'Field', name: {kind: 'Name', value: 'key'}},
{
kind: 'Field',
name: {kind: 'Name', value: 'activeRoot'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'clientCredentials'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'secrets'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'key'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ mutation CreateApp($appSource: AppSourceInput!, $name: String!) {
app {
id
key
activeRoot {
clientCredentials {
secrets {
key
}
}
}
}
userErrors {
category
Expand Down
9 changes: 3 additions & 6 deletions packages/app/src/cli/services/app/config/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function selectOrCreateRemoteAppToLinkTo(options: LinkOptions): Promise<{
let developerPlatformClient = await sniffServiceOptionsAndAppConfigToSelectPlatformClient(options)

const {creationOptions, appDirectory: possibleAppDirectory} = await getAppCreationDefaultsFromLocalApp(options)
const appDirectory = possibleAppDirectory || options.directory
const appDirectory = possibleAppDirectory ?? options.directory

if (options.apiKey) {
// Remote API Key provided by the caller, so use that app specifically
Expand Down Expand Up @@ -189,12 +189,9 @@ async function getAppCreationDefaultsFromLocalApp(options: LinkOptions): Promise
userProvidedConfigName: options.baseConfigName,
remoteFlags: undefined,
})
const configuration = app.configuration

if (!isCurrentAppSchema(configuration)) {
return {creationOptions: app.creationDefaultOptions(), appDirectory: app.directory}
}
return {creationOptions: appCreationDefaults}
return {creationOptions: app.creationDefaultOptions(), appDirectory: app.directory}

// eslint-disable-next-line no-catch-all/no-catch-all
} catch (error) {
return {creationOptions: appCreationDefaults}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ describe('createApp', () => {
publicApiVersions: [{handle: '2024-07'}, {handle: '2024-10'}, {handle: '2025-01'}, {handle: 'unstable'}],
}
vi.mocked(webhooksRequest).mockResolvedValueOnce(mockedApiVersionResult)
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce({appCreate: {app: {id: '1', key: 'key'}, userErrors: []}})
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce({
appCreate: {
app: {id: '1', key: 'key', activeRoot: {clientCredentials: {secrets: [{key: 'secret'}]}}},
userErrors: [],
},
})

// When
client.token = () => Promise.resolve('token')
Expand Down Expand Up @@ -347,7 +352,7 @@ describe('createApp', () => {
id: '1',
key: 'api-key',
apiKey: 'api-key',
apiSecretKeys: [],
apiSecretKeys: [{secret: 'secret'}],
flags: [],
grantedScopes: [],
organizationId: '1',
Expand All @@ -364,6 +369,11 @@ describe('createApp', () => {
app: {
id: expectedApp.id,
key: expectedApp.key,
activeRoot: {
clientCredentials: {
secrets: [{key: 'secret'}],
},
},
},
userErrors: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,12 @@ export class AppManagementClient implements DeveloperPlatformClient {
// Need to figure this out still
const flags = filterDisabledFlags([])
const createdApp = result.appCreate.app
const apiSecretKeys = createdApp.activeRoot.clientCredentials.secrets.map((secret) => ({secret: secret.key}))
return {
...createdApp,
title: name,
apiKey: createdApp.key,
apiSecretKeys: [],
apiSecretKeys,
grantedScopes: options?.scopesArray ?? [],
organizationId: org.id,
newApp: true,
Expand Down

0 comments on commit 58216c7

Please sign in to comment.