From c739eea81e787e003cded2b8d24ce0590f61dc9d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 May 2024 10:23:02 +0100 Subject: [PATCH] fix(cli): graphql api flag is respected during validation (#6615) During GraphQL deployment we validate APIs have unique dataset/tag. This check wasn't respecting the `--api` CLI flag. Ref CLDX-2142 --- .../cli/actions/graphql/deployApiAction.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/sanity/src/_internal/cli/actions/graphql/deployApiAction.ts b/packages/sanity/src/_internal/cli/actions/graphql/deployApiAction.ts index c789052c541..abcb321c5c9 100644 --- a/packages/sanity/src/_internal/cli/actions/graphql/deployApiAction.ts +++ b/packages/sanity/src/_internal/cli/actions/graphql/deployApiAction.ts @@ -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', @@ -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() const apiIds = new Set() 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('/') @@ -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(', ')}`) }