Skip to content

Commit

Permalink
Handle not having app ID available for function schema operations
Browse files Browse the repository at this point in the history
  • Loading branch information
amcaplan committed Dec 16, 2024
1 parent 7866253 commit 4413894
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
2 changes: 0 additions & 2 deletions packages/app/src/cli/services/generate-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ describe('generateSchemaService', () => {
},
app.configuration.client_id,
orgId,
app.configuration.app_id,
)
})
})
Expand Down Expand Up @@ -179,7 +178,6 @@ describe('generateSchemaService', () => {
},
app.configuration.client_id,
orgId,
app.configuration.app_id,
)
})
})
Expand Down
10 changes: 2 additions & 8 deletions packages/app/src/cli/services/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ interface GenerateSchemaOptions {
export async function generateSchemaService(options: GenerateSchemaOptions) {
const {extension, stdout, developerPlatformClient, app, orgId} = options
const apiKey = app.configuration.client_id
const appId = app.configuration.app_id
const {api_version: version, type, targeting} = extension.configuration
const usingTargets = Boolean(targeting?.length)
const definition = await (usingTargets
? generateSchemaFromTarget({
localIdentifier: extension.localIdentifier,
developerPlatformClient,
apiKey,
appId,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
target: targeting![0]!.target,
version,
Expand All @@ -39,7 +37,6 @@ export async function generateSchemaService(options: GenerateSchemaOptions) {
localIdentifier: extension.localIdentifier,
developerPlatformClient,
apiKey,
appId,
type,
version,
orgId,
Expand All @@ -58,7 +55,6 @@ interface BaseGenerateSchemaOptions {
localIdentifier: string
developerPlatformClient: DeveloperPlatformClient
apiKey: string
appId?: string
version: string
orgId: string
}
Expand All @@ -70,7 +66,6 @@ interface GenerateSchemaFromTargetOptions extends BaseGenerateSchemaOptions {
async function generateSchemaFromTarget({
localIdentifier,
developerPlatformClient,
appId,
apiKey,
target,
version,
Expand All @@ -81,7 +76,7 @@ async function generateSchemaFromTarget({
version,
}
// Api key required for partners reqs, can be removed once fully migrated to AMF
const definition = await developerPlatformClient.targetSchemaDefinition(variables, apiKey, orgId, appId)
const definition = await developerPlatformClient.targetSchemaDefinition(variables, apiKey, orgId)

if (!definition) {
throw new AbortError(
Expand All @@ -101,7 +96,6 @@ async function generateSchemaFromApiType({
localIdentifier,
developerPlatformClient,
apiKey,
appId,
version,
type,
orgId,
Expand All @@ -111,7 +105,7 @@ async function generateSchemaFromApiType({
type,
}

const definition = await developerPlatformClient.apiSchemaDefinition(variables, apiKey, orgId, appId)
const definition = await developerPlatformClient.apiSchemaDefinition(variables, apiKey, orgId)

if (!definition) {
throw new AbortError(
Expand Down
2 changes: 0 additions & 2 deletions packages/app/src/cli/utilities/developer-platform-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,11 @@ export interface DeveloperPlatformClient {
input: SchemaDefinitionByTargetQueryVariables,
apiKey: string,
organizationId: string,
appId?: string,
) => Promise<string | null>
apiSchemaDefinition: (
input: SchemaDefinitionByApiTypeQueryVariables,
apiKey: string,
organizationId: string,
appId?: string,
) => Promise<string | null>
migrateToUiExtension: (input: MigrateToUiExtensionVariables) => Promise<MigrateToUiExtensionSchema>
toExtensionGraphQLType: (input: string) => string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,12 +790,12 @@ export class AppManagementClient implements DeveloperPlatformClient {

async targetSchemaDefinition(
input: SchemaDefinitionByTargetQueryVariables,
_apiKey: string,
apiKey: string,
organizationId: string,
appId?: string,
): Promise<string | null> {
try {
const appIdNumber = String(numberFromGid(appId!))
const {app} = await this.activeAppVersionRawResult({apiKey, organizationId})
const appIdNumber = String(numberFromGid(app.id))
const token = await this.token()
const result = await functionsRequestDoc<SchemaDefinitionByTargetQuery, SchemaDefinitionByTargetQueryVariables>(
organizationId,
Expand All @@ -816,12 +816,12 @@ export class AppManagementClient implements DeveloperPlatformClient {

async apiSchemaDefinition(
input: SchemaDefinitionByApiTypeQueryVariables,
_apiKey: string,
apiKey: string,
organizationId: string,
appId?: string,
): Promise<string | null> {
try {
const appIdNumber = String(numberFromGid(appId!))
const {app} = await this.activeAppVersionRawResult({apiKey, organizationId})
const appIdNumber = String(numberFromGid(app.id!))

Check failure on line 824 in packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts#L824

[@typescript-eslint/no-unnecessary-type-assertion] This assertion is unnecessary since it does not change the type of the expression.
const token = await this.token()
const result = await functionsRequestDoc<SchemaDefinitionByApiTypeQuery, SchemaDefinitionByApiTypeQueryVariables>(
organizationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ export class PartnersClient implements DeveloperPlatformClient {
input: SchemaDefinitionByTargetQueryVariables,
apiKey: string,
_organizationId: string,
_appId?: string,
): Promise<string | null> {
// Ensures compatibility with existing partners requests
// Can remove once migrated to AMF
Expand Down

0 comments on commit 4413894

Please sign in to comment.