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'}, }) 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` }