From ed64efa3a4b72bab5e7641a65db8b7fc11070fa5 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Wed, 20 Nov 2024 16:05:50 -0500 Subject: [PATCH] fixes and cleanup --- packages/app/src/cli/commands/app/function/run.ts | 2 +- packages/app/src/cli/commands/app/function/schema.ts | 3 ++- packages/app/src/cli/services/function/common.ts | 9 ++++++--- packages/app/src/cli/services/generate-schema.ts | 12 +++++++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/app/src/cli/commands/app/function/run.ts b/packages/app/src/cli/commands/app/function/run.ts index 2c8d352f4d6..7653702d332 100644 --- a/packages/app/src/cli/commands/app/function/run.ts +++ b/packages/app/src/cli/commands/app/function/run.ts @@ -80,7 +80,7 @@ export default class FunctionRun extends AppCommand { const inputQueryPath = ourFunction?.configuration.targeting?.[0]?.input_query const queryPath = inputQueryPath && `${ourFunction?.directory}/${inputQueryPath}` - const schemaPath = await getOrGenerateSchemaPath(ourFunction, app, developerPlatformClient) + const schemaPath = await getOrGenerateSchemaPath(ourFunction, app, developerPlatformClient, app.configuration.organization_id || "2") await runFunction({ functionExtension: ourFunction, diff --git a/packages/app/src/cli/commands/app/function/schema.ts b/packages/app/src/cli/commands/app/function/schema.ts index 3b6ab786396..f9aeb62cb28 100644 --- a/packages/app/src/cli/commands/app/function/schema.ts +++ b/packages/app/src/cli/commands/app/function/schema.ts @@ -51,13 +51,14 @@ export default class FetchSchema extends AppCommand { path: flags.path, apiKey, userProvidedConfigName: flags.config, - callback: async (app, developerPlatformClient, ourFunction) => { + callback: async (app, developerPlatformClient, ourFunction, orgId) => { await generateSchemaService({ app, extension: ourFunction, developerPlatformClient, stdout: flags.stdout, path: flags.path, + orgId, }) return app }, diff --git a/packages/app/src/cli/services/function/common.ts b/packages/app/src/cli/services/function/common.ts index 49afb3c1ebe..665cd4e7dcb 100644 --- a/packages/app/src/cli/services/function/common.ts +++ b/packages/app/src/cli/services/function/common.ts @@ -35,9 +35,10 @@ export async function inFunctionContext({ app: AppLinkedInterface, developerPlatformClient: DeveloperPlatformClient, ourFunction: ExtensionInstance, + orgId: string ) => Promise }) { - const {app, developerPlatformClient} = await linkedAppContext({ + const {app, developerPlatformClient, organization} = await linkedAppContext({ directory: path, clientId: apiKey, forceRelink: false, @@ -50,14 +51,14 @@ export async function inFunctionContext({ const ourFunction = allFunctions.find((fun) => fun.directory === path) if (ourFunction) { - return callback(app, developerPlatformClient, ourFunction) + return callback(app, developerPlatformClient, ourFunction, organization.id) } else if (isTerminalInteractive()) { const selectedFunction = await renderAutocompletePrompt({ message: 'Which function?', choices: allFunctions.map((shopifyFunction) => ({label: shopifyFunction.handle, value: shopifyFunction})), }) - return callback(app, developerPlatformClient, selectedFunction) + return callback(app, developerPlatformClient, selectedFunction, organization.id) } else { throw new AbortError('Run this command from a function directory or use `--path` to specify a function directory.') } @@ -67,6 +68,7 @@ export async function getOrGenerateSchemaPath( extension: ExtensionInstance, app: AppLinkedInterface, developerPlatformClient: DeveloperPlatformClient, + orgId: string ): Promise { const path = joinPath(extension.directory, 'schema.graphql') if (await fileExists(path)) { @@ -79,6 +81,7 @@ export async function getOrGenerateSchemaPath( extension, stdout: false, path: extension.directory, + orgId, }) return (await fileExists(path)) ? path : undefined diff --git a/packages/app/src/cli/services/generate-schema.ts b/packages/app/src/cli/services/generate-schema.ts index b56382392cc..d8f70fdb9ac 100644 --- a/packages/app/src/cli/services/generate-schema.ts +++ b/packages/app/src/cli/services/generate-schema.ts @@ -15,10 +15,11 @@ interface GenerateSchemaOptions { stdout: boolean path: string developerPlatformClient: DeveloperPlatformClient + orgId: string } export async function generateSchemaService(options: GenerateSchemaOptions) { - const {extension, stdout, developerPlatformClient, app} = options + const {extension, stdout, developerPlatformClient, app, orgId} = options const apiKey = app.configuration.client_id const {api_version: version, type, targeting} = extension.configuration @@ -31,6 +32,7 @@ export async function generateSchemaService(options: GenerateSchemaOptions) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion target: targeting![0]!.target, version, + orgId, }) : generateSchemaFromApiType({ localIdentifier: extension.localIdentifier, @@ -38,6 +40,7 @@ export async function generateSchemaService(options: GenerateSchemaOptions) { apiKey, type, version, + orgId, })) if (stdout) { @@ -54,6 +57,7 @@ interface BaseGenerateSchemaOptions { developerPlatformClient: DeveloperPlatformClient apiKey: string version: string + orgId: string } interface GenerateSchemaFromTargetOptions extends BaseGenerateSchemaOptions { @@ -66,13 +70,14 @@ async function generateSchemaFromTarget({ apiKey, target, version, + orgId }: GenerateSchemaFromTargetOptions): Promise { const variables: TargetSchemaDefinitionQueryVariables = { apiKey, target, version, } - const definition = await developerPlatformClient.targetSchemaDefinition(variables, "2") + const definition = await developerPlatformClient.targetSchemaDefinition(variables, orgId) if (!definition) { throw new AbortError( @@ -94,6 +99,7 @@ async function generateSchemaFromApiType({ apiKey, version, type, + orgId }: GenerateSchemaFromType): Promise { const variables: ApiSchemaDefinitionQueryVariables = { apiKey, @@ -101,7 +107,7 @@ async function generateSchemaFromApiType({ type, } - const definition = await developerPlatformClient.apiSchemaDefinition(variables, "2") + const definition = await developerPlatformClient.apiSchemaDefinition(variables, orgId) if (!definition) { throw new AbortError(