Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port fetchThemeAssets / fetchChecksums to graphQL #4660

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

catlee
Copy link
Contributor

@catlee catlee commented Oct 16, 2024

WHY are these changes introduced?

Migrate off the REST Assets API and use graphQL instead.

WHAT is this pull request doing?

This PR adjusts the fetchThemeAsset and fetchChecksums method to use the OnlineStoreTheme.files field.

Where appropriate I've also updated callers to fetch multiple assets at once with fetchThemeAssets.

How to test your changes?

p shopify theme pull ... should fetch all the files from your theme to a local directory.

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@catlee catlee self-assigned this Oct 16, 2024
Copy link
Contributor

github-actions bot commented Oct 16, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.35% (-0.16% 🔻)
8375/11576
🟡 Branches
68.97% (-0.12% 🔻)
4114/5965
🟡 Functions
71.69% (-0.08% 🔻)
2188/3052
🟡 Lines
72.65% (-0.16% 🔻)
7919/10900
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / get_theme_file_bodies.ts
100% 100% 100% 100%
🟢
... / get_theme_file_checksums.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / ConcurrentOutput.tsx
98.39% (-1.61% 🔻)
90.91% (-4.55% 🔻)
100%
98.33% (-1.67% 🔻)
🟡
... / api.ts
59.78% (-21.57% 🔻)
63.41% (-18.73% 🔻)
68.18% (-8.29% 🔻)
60.92% (-20.9% 🔻)
🔴
... / factories.ts
42.11% (-15.79% 🔻)
33.33% (-6.67% 🔻)
60% (-20% 🔻)
50% (-18.75% 🔻)

Test suite run success

1903 tests passing in 865 suites.

Report generated by 🧪jest coverage report action from a274728

@catlee catlee force-pushed the catlee/theme_files_get branch 3 times, most recently from 25dadfa to dc7e4ed Compare October 16, 2024 15:50
@catlee catlee marked this pull request as ready for review October 16, 2024 16:00
@catlee catlee requested a review from a team as a code owner October 16, 2024 16:00
Copy link
Contributor

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/cli/api/graphql/admin/generated/get_theme_file_bodies.d.ts
import * as Types from './types.js';
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type GetThemeFileBodiesQueryVariables = Types.Exact<{
    id: Types.Scalars['ID']['input'];
    after?: Types.InputMaybe<Types.Scalars['String']['input']>;
    filenames?: Types.InputMaybe<Types.Scalars['String']['input'][] | Types.Scalars['String']['input']>;
}>;
export type GetThemeFileBodiesQuery = {
    theme?: {
        files?: {
            nodes: {
                filename: string;
                size: unknown;
                checksumMd5?: string | null;
                body: {
                    __typename: 'OnlineStoreThemeFileBodyBase64';
                    contentBase64: string;
                } | {
                    __typename: 'OnlineStoreThemeFileBodyText';
                    content: string;
                } | {
                    __typename: 'OnlineStoreThemeFileBodyUrl';
                    url: string;
                };
            }[];
            userErrors: {
                filename: string;
                code: Types.OnlineStoreThemeFileResultType;
            }[];
            pageInfo: {
                hasNextPage: boolean;
                endCursor?: string | null;
            };
        } | null;
    } | null;
};
export declare const GetThemeFileBodies: DocumentNode<GetThemeFileBodiesQuery, Types.Exact<{
    id: Types.Scalars['ID']['input'];
    after?: Types.InputMaybe<string> | undefined;
    filenames?: Types.InputMaybe<string | string[]> | undefined;
}>>;
packages/cli-kit/dist/cli/api/graphql/admin/generated/get_theme_file_checksums.d.ts
import * as Types from './types.js';
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type GetThemeFileChecksumsQueryVariables = Types.Exact<{
    id: Types.Scalars['ID']['input'];
    after?: Types.InputMaybe<Types.Scalars['String']['input']>;
}>;
export type GetThemeFileChecksumsQuery = {
    theme?: {
        files?: {
            nodes: {
                filename: string;
                size: unknown;
                checksumMd5?: string | null;
            }[];
            userErrors: {
                filename: string;
                code: Types.OnlineStoreThemeFileResultType;
            }[];
            pageInfo: {
                hasNextPage: boolean;
                endCursor?: string | null;
            };
        } | null;
    } | null;
};
export declare const GetThemeFileChecksums: DocumentNode<GetThemeFileChecksumsQuery, Types.Exact<{
    id: Types.Scalars['ID']['input'];
    after?: Types.InputMaybe<string> | undefined;
}>>;

Existing type declarations

packages/cli-kit/dist/public/node/themes/api.d.ts
@@ -5,7 +5,7 @@ export type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'va
 export declare function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined>;
 export declare function fetchThemes(session: AdminSession): Promise<Theme[]>;
 export declare function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined>;
-export declare function fetchThemeAsset(id: number, key: Key, session: AdminSession): Promise<ThemeAsset | undefined>;
+export declare function fetchThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<ThemeAsset[]>;
 export declare function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean>;
 export declare function bulkUploadThemeAssets(id: number, assets: AssetParams[], session: AdminSession): Promise<Result[]>;
 export declare function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant