diff --git a/packages/cli-kit/src/public/node/api/admin.ts b/packages/cli-kit/src/public/node/api/admin.ts index 8244d4724c4..6ab65d863c7 100644 --- a/packages/cli-kit/src/public/node/api/admin.ts +++ b/packages/cli-kit/src/public/node/api/admin.ts @@ -9,6 +9,8 @@ import {normalizeStoreFqdn} from '../context/fqdn.js' import {ClientError, Variables} from 'graphql-request' import {TypedDocumentNode} from '@graphql-typed-document-node/core' +const LatestApiVersionByFQDN = new Map() + /** * Executes a GraphQL query against the Admin API. * @@ -42,8 +44,8 @@ export async function adminRequestDoc( version?: string, responseOptions?: GraphQLResponseOptions, ): Promise { - let apiVersion = version - if (!version) { + let apiVersion = version || LatestApiVersionByFQDN.get(session.storeFqdn) + if (!apiVersion) { apiVersion = await fetchLatestSupportedApiVersion(session) } const store = await normalizeStoreFqdn(session.storeFqdn) @@ -64,8 +66,9 @@ export async function adminRequestDoc( */ async function fetchLatestSupportedApiVersion(session: AdminSession): Promise { const apiVersions = await supportedApiVersions(session) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return apiVersions.reverse()[0]! + const latest = apiVersions.reverse()[0]! + LatestApiVersionByFQDN.set(session.storeFqdn, latest) + return latest } /**