From 1bc427650c3229358e6cbeeb3b834d98fdf5d09d Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Wed, 15 Jan 2025 13:27:58 +0100 Subject: [PATCH 1/2] [3.73] Fix `shopify theme dev` to no longer fail when development themes expire in internationalized stores --- .changeset/lemon-pants-add.md | 6 +++ .../src/public/node/themes/api.test.ts | 2 +- .../cli-kit/src/public/node/themes/api.ts | 39 ++++++++++--------- 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 .changeset/lemon-pants-add.md diff --git a/.changeset/lemon-pants-add.md b/.changeset/lemon-pants-add.md new file mode 100644 index 00000000000..5b4b91e14fe --- /dev/null +++ b/.changeset/lemon-pants-add.md @@ -0,0 +1,6 @@ +--- +'@shopify/cli-kit': patch +'@shopify/theme': patch +--- + +Fix `shopify theme dev` to no longer fail when development themes expire in internationalized stores diff --git a/packages/cli-kit/src/public/node/themes/api.test.ts b/packages/cli-kit/src/public/node/themes/api.test.ts index 66e2397786d..c32c2687cb0 100644 --- a/packages/cli-kit/src/public/node/themes/api.test.ts +++ b/packages/cli-kit/src/public/node/themes/api.test.ts @@ -59,7 +59,7 @@ describe('fetchTheme', () => { test('returns undefined when a theme is not found', async () => { const errorResponse = { status: 200, - errors: [{message: 'Theme does not exist'} as any], + errors: [{message: 'Tema não existe'} as any], } vi.mocked(adminRequestDoc).mockRejectedValue(new ClientError(errorResponse, {query: ''})) diff --git a/packages/cli-kit/src/public/node/themes/api.ts b/packages/cli-kit/src/public/node/themes/api.ts index 0423f433e00..b5665e44f6b 100644 --- a/packages/cli-kit/src/public/node/themes/api.ts +++ b/packages/cli-kit/src/public/node/themes/api.ts @@ -25,33 +25,36 @@ import {buildTheme} from '@shopify/cli-kit/node/themes/factories' import {Result, Checksum, Key, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types' import {outputDebug} from '@shopify/cli-kit/node/output' import {sleep} from '@shopify/cli-kit/node/system' -import {ClientError} from 'graphql-request' export type ThemeParams = Partial> export type AssetParams = Pick & Partial> export async function fetchTheme(id: number, session: AdminSession): Promise { + const gid = composeThemeGid(id) + try { - const response = await adminRequestDoc(GetTheme, session, {id: composeThemeGid(id)}, undefined, { + const {theme} = await adminRequestDoc(GetTheme, session, {id: gid}, undefined, { handleErrors: false, }) - const {theme} = response - if (!theme) { - return undefined - } - return buildTheme({ - id: parseGid(theme.id), - processing: theme.processing, - role: theme.role.toLowerCase(), - name: theme.name, - }) - } catch (error) { - if (error instanceof ClientError) { - if (error.response?.errors?.[0]?.message === 'Theme does not exist') { - return undefined - } + + if (theme) { + return buildTheme({ + id: parseGid(theme.id), + processing: theme.processing, + role: theme.role.toLowerCase(), + name: theme.name, + }) } - throw new AbortError(`Failed to fetch theme: ${id}`) + + // eslint-disable-next-line no-catch-all/no-catch-all + } catch (_error) { + /** + * Consumers of this and other theme APIs in this file expect either a theme + * or `undefined`. + * + * Error handlers should not inspect GraphQL error messages directly, as + * they are internationalized. + */ } } From 59feaa7794b160a95078465e07cb31042680bb0c Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Thu, 16 Jan 2025 10:18:45 +0100 Subject: [PATCH 2/2] `graphql-codegen` --- packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts b/packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts index ab109b34c12..6a831d59181 100644 --- a/packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts +++ b/packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts @@ -250,7 +250,7 @@ export type ThemeRole = * publishing are restricted until the merchant resolves the licensing issue. */ | 'LOCKED' - /** TThe currently published theme. There can only be one main theme at any time. */ + /** The currently published theme. There can only be one main theme at any time. */ | 'MAIN' /** The currently published theme that is only accessible to a mobile client. */ | 'MOBILE'