From a06733352d99d63580cf1b691a9220a5b4149a01 Mon Sep 17 00:00:00 2001 From: Chris AtLee Date: Wed, 16 Oct 2024 16:57:11 -0400 Subject: [PATCH] Cache latest API versions by fqdn --- packages/cli-kit/src/public/node/api/admin.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 } /**