Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mssalemi committed Nov 20, 2024
1 parent 7587dbc commit ed64efa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/cli/commands/app/function/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/commands/app/function/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/cli/services/function/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ export async function inFunctionContext({
app: AppLinkedInterface,
developerPlatformClient: DeveloperPlatformClient,
ourFunction: ExtensionInstance<FunctionConfigType>,
orgId: string
) => Promise<AppLinkedInterface>
}) {
const {app, developerPlatformClient} = await linkedAppContext({
const {app, developerPlatformClient, organization} = await linkedAppContext({
directory: path,
clientId: apiKey,
forceRelink: false,
Expand All @@ -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.')
}
Expand All @@ -67,6 +68,7 @@ export async function getOrGenerateSchemaPath(
extension: ExtensionInstance<FunctionConfigType>,
app: AppLinkedInterface,
developerPlatformClient: DeveloperPlatformClient,
orgId: string
): Promise<string | undefined> {
const path = joinPath(extension.directory, 'schema.graphql')
if (await fileExists(path)) {
Expand All @@ -79,6 +81,7 @@ export async function getOrGenerateSchemaPath(
extension,
stdout: false,
path: extension.directory,
orgId,
})

return (await fileExists(path)) ? path : undefined
Expand Down
12 changes: 9 additions & 3 deletions packages/app/src/cli/services/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,13 +32,15 @@ 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,
developerPlatformClient,
apiKey,
type,
version,
orgId,
}))

if (stdout) {
Expand All @@ -54,6 +57,7 @@ interface BaseGenerateSchemaOptions {
developerPlatformClient: DeveloperPlatformClient
apiKey: string
version: string
orgId: string
}

interface GenerateSchemaFromTargetOptions extends BaseGenerateSchemaOptions {
Expand All @@ -66,13 +70,14 @@ async function generateSchemaFromTarget({
apiKey,
target,
version,
orgId
}: GenerateSchemaFromTargetOptions): Promise<string> {
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(
Expand All @@ -94,14 +99,15 @@ async function generateSchemaFromApiType({
apiKey,
version,
type,
orgId
}: GenerateSchemaFromType): Promise<string> {
const variables: ApiSchemaDefinitionQueryVariables = {
apiKey,
version,
type,
}

const definition = await developerPlatformClient.apiSchemaDefinition(variables, "2")
const definition = await developerPlatformClient.apiSchemaDefinition(variables, orgId)

if (!definition) {
throw new AbortError(
Expand Down

0 comments on commit ed64efa

Please sign in to comment.