Skip to content

Commit

Permalink
Merge pull request #4792 from Shopify/catlee/theme_files_put
Browse files Browse the repository at this point in the history
Use graphQL to upload theme files
  • Loading branch information
karreiro authored Dec 2, 2024
2 parents 7fc88c3 + 11fd136 commit c202990
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import * as Types from './types.js'

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

export type ThemeFilesUpsertMutationVariables = Types.Exact<{
files: Types.OnlineStoreThemeFilesUpsertFileInput[] | Types.OnlineStoreThemeFilesUpsertFileInput
themeId: Types.Scalars['ID']['input']
}>

export type ThemeFilesUpsertMutation = {
themeFilesUpsert?: {
upsertedThemeFiles?: {filename: string}[] | null
userErrors: {filename?: string | null; message: string}[]
} | null
}

export const ThemeFilesUpsert = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'mutation',
name: {kind: 'Name', value: 'themeFilesUpsert'},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'files'}},
type: {
kind: 'NonNullType',
type: {
kind: 'ListType',
type: {
kind: 'NonNullType',
type: {kind: 'NamedType', name: {kind: 'Name', value: 'OnlineStoreThemeFilesUpsertFileInput'}},
},
},
},
},
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'themeId'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'ID'}}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'themeFilesUpsert'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'files'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'files'}},
},
{
kind: 'Argument',
name: {kind: 'Name', value: 'themeId'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'themeId'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'upsertedThemeFiles'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'filename'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{
kind: 'Field',
name: {kind: 'Name', value: 'userErrors'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'filename'}},
{kind: 'Field', name: {kind: 'Name', value: 'message'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
],
},
},
],
} as unknown as DocumentNode<ThemeFilesUpsertMutation, ThemeFilesUpsertMutationVariables>
25 changes: 25 additions & 0 deletions packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ export type Scalars = {
UtcOffset: {input: any; output: any}
}

/** The input fields for the theme file body. */
export type OnlineStoreThemeFileBodyInput = {
/** The input type of the theme file body. */
type: OnlineStoreThemeFileBodyInputType
/** The body of the theme file. */
value: Scalars['String']['input']
}

/** The input type for a theme file body. */
export type OnlineStoreThemeFileBodyInputType =
/** The base64 encoded body of a theme file. */
| 'BASE64'
/** The text body of the theme file. */
| 'TEXT'
/** The url of the body of a theme file. */
| 'URL'

/** Type of a theme file operation result. */
export type OnlineStoreThemeFileResultType =
/** Operation was malformed or invalid. */
Expand All @@ -137,6 +154,14 @@ export type OnlineStoreThemeFileResultType =
/** Operation could not be processed due to issues with input data. */
| 'UNPROCESSABLE_ENTITY'

/** The input fields for the file to create or update. */
export type OnlineStoreThemeFilesUpsertFileInput = {
/** The body of the theme file. */
body: OnlineStoreThemeFileBodyInput
/** The filename of the theme file. */
filename: Scalars['String']['input']
}

/** The input fields for Theme attributes to update. */
export type OnlineStoreThemeInput = {
/** The new name of the theme. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation themeFilesUpsert($files: [OnlineStoreThemeFilesUpsertFileInput!]!, $themeId: ID!) {
themeFilesUpsert(files: $files, themeId: $themeId) {
upsertedThemeFiles {
filename
}
userErrors {
filename
message
}
}
}
2 changes: 1 addition & 1 deletion packages/cli-kit/src/private/node/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function errorsIncludeStatus429(error: ClientError): boolean {
}

// GraphQL returns a 401 with a string error message when auth fails
// Therefore error.response.errros can be a string or GraphQLError[]
// Therefore error.response.errors can be a string or GraphQLError[]
if (typeof error.response.errors === 'string') {
return false
}
Expand Down
Loading

0 comments on commit c202990

Please sign in to comment.