From 1e37b3889b9afbd47f5482a5f0f7dc39778f4c11 Mon Sep 17 00:00:00 2001 From: Shaun Stanworth Date: Tue, 22 Oct 2024 19:25:36 +0100 Subject: [PATCH 1/2] Log more information for store connection issues --- packages/cli-kit/src/public/node/api/admin.ts | 20 +++++++++++++++---- 1 file changed, 16 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 f3f2b8419b..8244d4724c 100644 --- a/packages/cli-kit/src/public/node/api/admin.ts +++ b/packages/cli-kit/src/public/node/api/admin.ts @@ -5,6 +5,7 @@ import {BugError, AbortError} from '../error.js' import {restRequestBody, restRequestHeaders, restRequestUrl} from '../../../private/node/api/rest.js' import {fetch} from '../http.js' import {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js' +import {normalizeStoreFqdn} from '../context/fqdn.js' import {ClientError, Variables} from 'graphql-request' import {TypedDocumentNode} from '@graphql-typed-document-node/core' @@ -19,7 +20,8 @@ import {TypedDocumentNode} from '@graphql-typed-document-node/core' export async function adminRequest(query: string, session: AdminSession, variables?: GraphQLVariables): Promise { const api = 'Admin' const version = await fetchLatestSupportedApiVersion(session) - const url = adminUrl(session.storeFqdn, version) + const store = await normalizeStoreFqdn(session.storeFqdn) + const url = adminUrl(store, version) return graphqlRequest({query, api, url, token: session.token, variables}) } @@ -44,8 +46,9 @@ export async function adminRequestDoc( if (!version) { apiVersion = await fetchLatestSupportedApiVersion(session) } + const store = await normalizeStoreFqdn(session.storeFqdn) const opts = { - url: adminUrl(session.storeFqdn, apiVersion), + url: adminUrl(store, apiVersion), api: 'Admin', token: session.token, } @@ -99,8 +102,17 @@ async function fetchApiVersions(session: AdminSession): Promise { )})`, outputContent`If you're not the owner, create a dev store staff account for yourself`, ) + } else if (error instanceof ClientError) { + throw new BugError( + `Unknown client error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`, + ) + } else { + throw new BugError( + `Unknown error connecting to your store ${session.storeFqdn}: ${ + error instanceof Error ? error.message : String(error) + }`, + ) } - throw new BugError(`Unknown error connecting to your store`) } } @@ -112,7 +124,7 @@ async function fetchApiVersions(session: AdminSession): Promise { * @returns - Admin API URL. */ export function adminUrl(store: string, version: string | undefined): string { - const realVersion = version || 'unstable' + const realVersion = version ?? 'unstable' return `https://${store}/admin/api/${realVersion}/graphql.json` } From 58862fd57727c3d6e6f28a54071fcfd1f705651c Mon Sep 17 00:00:00 2001 From: Shaun Stanworth Date: Wed, 23 Oct 2024 10:32:59 +0100 Subject: [PATCH 2/2] Correct test case --- packages/cli-kit/src/public/node/api/admin.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-kit/src/public/node/api/admin.test.ts b/packages/cli-kit/src/public/node/api/admin.test.ts index e281d45374..f3e6ab2618 100644 --- a/packages/cli-kit/src/public/node/api/admin.test.ts +++ b/packages/cli-kit/src/public/node/api/admin.test.ts @@ -56,7 +56,7 @@ describe('admin-graphql-api', () => { expect(graphqlRequest).toHaveBeenLastCalledWith({ query: 'query', api: 'Admin', - url: 'https://store/admin/api/2022-01/graphql.json', + url: 'https://store.myshopify.com/admin/api/2022-01/graphql.json', token, variables: {variables: 'variables'}, })