Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clear mutation #2353

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/app/src/cli/api/graphql/clear_requested_scopes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {gql} from 'graphql-request'

export const clearRequestedScopes = gql`
mutation appRequestedAccessScopesClear($apiKey: String!) {
appRequestedAccessScopesClear(input: {apiKey: $apiKey}) {
userErrors {
message
field
}
}
}
`

export interface ClearScopesVariables {
apiKey: string
}

export interface ClearScopesSchema {
appRequestedAccessScopesClear: {
userErrors: {
field: string[]
message: string
}[]
}
}
4 changes: 4 additions & 0 deletions packages/app/src/cli/services/app/config/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ describe('pushConfig', () => {
webhookApiVersion: '04-2023',
})

expect(vi.mocked(partnersRequest).mock.calls[2]![2]!).toEqual({
apiKey: '12345',
})

expect(renderSuccess).toHaveBeenCalledWith({
headline: 'Updated app configuration for my app',
body: ['shopify.app.development.toml configuration is now live on Shopify.'],
Expand Down
17 changes: 12 additions & 5 deletions packages/app/src/cli/services/app/config/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {PushConfig, PushConfigSchema, PushConfigVariables} from '../../../api/graphql/push_config.js'
import {ClearScopesSchema, clearRequestedScopes} from '../../../api/graphql/clear_requested_scopes.js'
import {App, GetConfig, GetConfigQuerySchema} from '../../../api/graphql/get_config.js'
import {
AppConfiguration,
Expand All @@ -21,27 +22,33 @@ export interface Options {
export async function pushConfig({configuration, configurationPath}: Options) {
if (isCurrentAppSchema(configuration)) {
const token = await ensureAuthenticatedPartners()
const mutation = PushConfig
const query = GetConfig

const configFileName = basename(configurationPath)

const queryVariables = {apiKey: configuration.client_id}
const queryResult: GetConfigQuerySchema = await partnersRequest(query, token, queryVariables)
const queryResult: GetConfigQuerySchema = await partnersRequest(GetConfig, token, queryVariables)

if (!queryResult.app) abort("Couldn't find app. Make sure you have a valid client ID.")

const {app} = queryResult

const variables = getMutationVars(app, configuration)

const result: PushConfigSchema = await partnersRequest(mutation, token, variables)
const result: PushConfigSchema = await partnersRequest(PushConfig, token, variables)

if (result.appUpdate.userErrors.length > 0) {
const errors = result.appUpdate.userErrors.map((error) => error.message).join(', ')
abort(errors)
}

if (usesLegacyScopesBehavior(configuration)) {
const clearResult: ClearScopesSchema = await partnersRequest(clearRequestedScopes, token, {apiKey: app.apiKey})

if (clearResult.appRequestedAccessScopesClear?.userErrors?.length > 0) {
const errors = result.appUpdate.userErrors.map((error) => error.message).join(', ')
abort(errors)
}
}

renderSuccess({
headline: `Updated app configuration for ${configuration.name}`,
body: [`${configFileName} configuration is now live on Shopify.`],
Expand Down