Skip to content

Commit

Permalink
fix(cli): graphql api flag is respected during validation (#6615)
Browse files Browse the repository at this point in the history
During GraphQL deployment we validate APIs have unique dataset/tag. This check wasn't respecting the `--api` CLI flag.

Ref CLDX-2142
  • Loading branch information
mwain committed May 22, 2024
1 parent 10b596a commit c739eea
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ export default async function deployGraphQLApiAction(
}).config({apiVersion: '2023-08-01'})

const apiDefs = await getGraphQLAPIs(context)
const hasMultipleApis = apiDefs.length > 1 || (flags.api && flags.api.length > 1)

let hasMultipleApis = apiDefs.length > 1
if (flags.api) {
hasMultipleApis = flags.api.length > 1
}

const usedFlags = [
datasetFlag && '--dataset',
tagFlag && '--tag',
Expand Down Expand Up @@ -97,9 +102,19 @@ export default async function deployGraphQLApiAction(

const deployTasks: DeployTask[] = []

for (const apiId of onlyApis || []) {
if (!apiDefs.some((apiDef) => apiDef.id === apiId)) {
throw new Error(`GraphQL API with id "${apiId}" not found`)
}
}

const apiNames = new Set<string>()
const apiIds = new Set<string>()
for (const apiDef of apiDefs) {
if (onlyApis && (!apiDef.id || !onlyApis.includes(apiDef.id))) {
continue
}

const dataset = datasetFlag || apiDef.dataset
const tag = tagFlag || apiDef.tag || 'default'
const apiName = [dataset, tag].join('/')
Expand All @@ -124,12 +139,6 @@ export default async function deployGraphQLApiAction(
apiNames.add(apiName)
}

for (const apiId of onlyApis || []) {
if (!apiDefs.some((apiDef) => apiDef.id === apiId)) {
throw new Error(`GraphQL API with id "${apiId}" not found`)
}
}

if (onlyApis) {
output.warn(`Deploying only specified APIs: ${onlyApis.join(', ')}`)
}
Expand Down

0 comments on commit c739eea

Please sign in to comment.