Skip to content

Commit d8db357

Browse files
committed
implement mutation support for BulkOps CLI command
1 parent 45fe1ee commit d8db357

File tree

17 files changed

+822
-34
lines changed

17 files changed

+822
-34
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-redundant-type-constituents */
2+
import * as Types from './types.js'
3+
4+
import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'
5+
6+
export type BulkOperationRunMutationMutationVariables = Types.Exact<{
7+
mutation: Types.Scalars['String']['input']
8+
stagedUploadPath: Types.Scalars['String']['input']
9+
clientIdentifier?: Types.InputMaybe<Types.Scalars['String']['input']>
10+
}>
11+
12+
export type BulkOperationRunMutationMutation = {
13+
bulkOperationRunMutation?: {
14+
bulkOperation?: {
15+
completedAt?: unknown | null
16+
createdAt: unknown
17+
errorCode?: Types.BulkOperationErrorCode | null
18+
fileSize?: unknown | null
19+
id: string
20+
objectCount: unknown
21+
partialDataUrl?: string | null
22+
query: string
23+
rootObjectCount: unknown
24+
status: Types.BulkOperationStatus
25+
type: Types.BulkOperationType
26+
url?: string | null
27+
} | null
28+
userErrors: {code?: Types.BulkMutationErrorCode | null; field?: string[] | null; message: string}[]
29+
} | null
30+
}
31+
32+
export const BulkOperationRunMutation = {
33+
kind: 'Document',
34+
definitions: [
35+
{
36+
kind: 'OperationDefinition',
37+
operation: 'mutation',
38+
name: {kind: 'Name', value: 'BulkOperationRunMutation'},
39+
variableDefinitions: [
40+
{
41+
kind: 'VariableDefinition',
42+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'mutation'}},
43+
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
44+
},
45+
{
46+
kind: 'VariableDefinition',
47+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'stagedUploadPath'}},
48+
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
49+
},
50+
{
51+
kind: 'VariableDefinition',
52+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'clientIdentifier'}},
53+
type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}},
54+
},
55+
],
56+
selectionSet: {
57+
kind: 'SelectionSet',
58+
selections: [
59+
{
60+
kind: 'Field',
61+
name: {kind: 'Name', value: 'bulkOperationRunMutation'},
62+
arguments: [
63+
{
64+
kind: 'Argument',
65+
name: {kind: 'Name', value: 'mutation'},
66+
value: {kind: 'Variable', name: {kind: 'Name', value: 'mutation'}},
67+
},
68+
{
69+
kind: 'Argument',
70+
name: {kind: 'Name', value: 'stagedUploadPath'},
71+
value: {kind: 'Variable', name: {kind: 'Name', value: 'stagedUploadPath'}},
72+
},
73+
{
74+
kind: 'Argument',
75+
name: {kind: 'Name', value: 'groupObjects'},
76+
value: {kind: 'BooleanValue', value: false},
77+
},
78+
{
79+
kind: 'Argument',
80+
name: {kind: 'Name', value: 'clientIdentifier'},
81+
value: {kind: 'Variable', name: {kind: 'Name', value: 'clientIdentifier'}},
82+
},
83+
],
84+
selectionSet: {
85+
kind: 'SelectionSet',
86+
selections: [
87+
{
88+
kind: 'Field',
89+
name: {kind: 'Name', value: 'bulkOperation'},
90+
selectionSet: {
91+
kind: 'SelectionSet',
92+
selections: [
93+
{kind: 'Field', name: {kind: 'Name', value: 'completedAt'}},
94+
{kind: 'Field', name: {kind: 'Name', value: 'createdAt'}},
95+
{kind: 'Field', name: {kind: 'Name', value: 'errorCode'}},
96+
{kind: 'Field', name: {kind: 'Name', value: 'fileSize'}},
97+
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
98+
{kind: 'Field', name: {kind: 'Name', value: 'objectCount'}},
99+
{kind: 'Field', name: {kind: 'Name', value: 'partialDataUrl'}},
100+
{kind: 'Field', name: {kind: 'Name', value: 'query'}},
101+
{kind: 'Field', name: {kind: 'Name', value: 'rootObjectCount'}},
102+
{kind: 'Field', name: {kind: 'Name', value: 'status'}},
103+
{kind: 'Field', name: {kind: 'Name', value: 'type'}},
104+
{kind: 'Field', name: {kind: 'Name', value: 'url'}},
105+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
106+
],
107+
},
108+
},
109+
{
110+
kind: 'Field',
111+
name: {kind: 'Name', value: 'userErrors'},
112+
selectionSet: {
113+
kind: 'SelectionSet',
114+
selections: [
115+
{kind: 'Field', name: {kind: 'Name', value: 'code'}},
116+
{kind: 'Field', name: {kind: 'Name', value: 'field'}},
117+
{kind: 'Field', name: {kind: 'Name', value: 'message'}},
118+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
119+
],
120+
},
121+
},
122+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
123+
],
124+
},
125+
},
126+
],
127+
},
128+
},
129+
],
130+
} as unknown as DocumentNode<BulkOperationRunMutationMutation, BulkOperationRunMutationMutationVariables>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
2+
import * as Types from './types.js'
3+
4+
import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'
5+
6+
export type StagedUploadsCreateMutationVariables = Types.Exact<{
7+
input: Types.StagedUploadInput[] | Types.StagedUploadInput
8+
}>
9+
10+
export type StagedUploadsCreateMutation = {
11+
stagedUploadsCreate?: {
12+
stagedTargets?:
13+
| {
14+
url?: string | null
15+
resourceUrl?: string | null
16+
parameters: {name: string; value: string}[]
17+
}[]
18+
| null
19+
userErrors: {field?: string[] | null; message: string}[]
20+
} | null
21+
}
22+
23+
export const StagedUploadsCreate = {
24+
kind: 'Document',
25+
definitions: [
26+
{
27+
kind: 'OperationDefinition',
28+
operation: 'mutation',
29+
name: {kind: 'Name', value: 'StagedUploadsCreate'},
30+
variableDefinitions: [
31+
{
32+
kind: 'VariableDefinition',
33+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'input'}},
34+
type: {
35+
kind: 'NonNullType',
36+
type: {
37+
kind: 'ListType',
38+
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'StagedUploadInput'}}},
39+
},
40+
},
41+
},
42+
],
43+
selectionSet: {
44+
kind: 'SelectionSet',
45+
selections: [
46+
{
47+
kind: 'Field',
48+
name: {kind: 'Name', value: 'stagedUploadsCreate'},
49+
arguments: [
50+
{
51+
kind: 'Argument',
52+
name: {kind: 'Name', value: 'input'},
53+
value: {kind: 'Variable', name: {kind: 'Name', value: 'input'}},
54+
},
55+
],
56+
selectionSet: {
57+
kind: 'SelectionSet',
58+
selections: [
59+
{
60+
kind: 'Field',
61+
name: {kind: 'Name', value: 'stagedTargets'},
62+
selectionSet: {
63+
kind: 'SelectionSet',
64+
selections: [
65+
{kind: 'Field', name: {kind: 'Name', value: 'url'}},
66+
{kind: 'Field', name: {kind: 'Name', value: 'resourceUrl'}},
67+
{
68+
kind: 'Field',
69+
name: {kind: 'Name', value: 'parameters'},
70+
selectionSet: {
71+
kind: 'SelectionSet',
72+
selections: [
73+
{kind: 'Field', name: {kind: 'Name', value: 'name'}},
74+
{kind: 'Field', name: {kind: 'Name', value: 'value'}},
75+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
76+
],
77+
},
78+
},
79+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
80+
],
81+
},
82+
},
83+
{
84+
kind: 'Field',
85+
name: {kind: 'Name', value: 'userErrors'},
86+
selectionSet: {
87+
kind: 'SelectionSet',
88+
selections: [
89+
{kind: 'Field', name: {kind: 'Name', value: 'field'}},
90+
{kind: 'Field', name: {kind: 'Name', value: 'message'}},
91+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
92+
],
93+
},
94+
},
95+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
96+
],
97+
},
98+
},
99+
],
100+
},
101+
},
102+
],
103+
} as unknown as DocumentNode<StagedUploadsCreateMutation, StagedUploadsCreateMutationVariables>

packages/app/src/cli/api/graphql/bulk-operations/generated/types.d.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ export type Scalars = {
120120
UtcOffset: {input: any; output: any}
121121
}
122122

123+
/** Possible error codes that can be returned by `BulkMutationUserError`. */
124+
export type BulkMutationErrorCode =
125+
/**
126+
* There was a problem reading the JSONL file. This error might be intermittent,
127+
* so you can try performing the same query again.
128+
*/
129+
| 'INTERNAL_FILE_SERVER_ERROR'
130+
/** The operation did not run because the mutation is invalid. Check your mutation syntax and try again. */
131+
| 'INVALID_MUTATION'
132+
/** The JSONL file submitted via the `stagedUploadsCreate` mutation is invalid. Update the file and try again. */
133+
| 'INVALID_STAGED_UPLOAD_FILE'
134+
/** Bulk operations limit reached. Please try again later. */
135+
| 'LIMIT_REACHED'
136+
/**
137+
* The JSONL file could not be found. Try [uploading the file](https://shopify.dev/api/usage/bulk-operations/imports#generate-the-uploaded-url-and-parameters)
138+
* again, and check that you've entered the URL correctly for the
139+
* `stagedUploadPath` mutation argument.
140+
*/
141+
| 'NO_SUCH_FILE'
142+
/**
143+
* The operation did not run because another bulk mutation is already running.
144+
* [Wait for the operation to finish](https://shopify.dev/api/usage/bulk-operations/imports#wait-for-the-operation-to-finish)
145+
* before retrying this operation.
146+
*/
147+
| 'OPERATION_IN_PROGRESS'
148+
123149
/** Error codes for failed bulk operations. */
124150
export type BulkOperationErrorCode =
125151
/**
@@ -177,3 +203,123 @@ export type BulkOperationUserErrorCode =
177203
| 'LIMIT_REACHED'
178204
/** A bulk operation is already in progress. */
179205
| 'OPERATION_IN_PROGRESS'
206+
207+
/**
208+
* The possible HTTP methods that can be used when sending a request to upload a file using information from a
209+
* [StagedMediaUploadTarget](https://shopify.dev/api/admin-graphql/latest/objects/StagedMediaUploadTarget).
210+
*/
211+
export type StagedUploadHttpMethodType =
212+
/** The POST HTTP method. */
213+
| 'POST'
214+
/** The PUT HTTP method. */
215+
| 'PUT'
216+
217+
/** The input fields for generating staged upload targets. */
218+
export type StagedUploadInput = {
219+
/**
220+
* The size of the file to upload, in bytes. This is required when the request's resource property is set to
221+
* [VIDEO](https://shopify.dev/api/admin-graphql/latest/enums/StagedUploadTargetGenerateUploadResource#value-video)
222+
* or [MODEL_3D](https://shopify.dev/api/admin-graphql/latest/enums/StagedUploadTargetGenerateUploadResource#value-model3d).
223+
*/
224+
fileSize?: InputMaybe<Scalars['UnsignedInt64']['input']>
225+
/** The file's name and extension. */
226+
filename: Scalars['String']['input']
227+
/**
228+
* The HTTP method to be used when sending a request to upload the file using the returned staged
229+
* upload target.
230+
*/
231+
httpMethod?: InputMaybe<StagedUploadHttpMethodType>
232+
/** The file's MIME type. */
233+
mimeType: Scalars['String']['input']
234+
/** The file's intended Shopify resource type. */
235+
resource: StagedUploadTargetGenerateUploadResource
236+
}
237+
238+
/** The resource type to receive. */
239+
export type StagedUploadTargetGenerateUploadResource =
240+
/**
241+
* Represents bulk mutation variables.
242+
*
243+
* For example, bulk mutation variables can be used for bulk operations using the
244+
* [bulkOperationRunMutation mutation](https://shopify.dev/api/admin-graphql/latest/mutations/bulkOperationRunMutation).
245+
*/
246+
| 'BULK_MUTATION_VARIABLES'
247+
/**
248+
* An image associated with a collection.
249+
*
250+
* For example, after uploading an image, you can use the
251+
* [collectionUpdate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/collectionUpdate)
252+
* to add the image to a collection.
253+
*/
254+
| 'COLLECTION_IMAGE'
255+
/**
256+
* Represents a file associated with a dispute.
257+
*
258+
* For example, after uploading the file, you can add the file to a dispute using the
259+
* [disputeEvidenceUpdate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/disputeEvidenceUpdate).
260+
*/
261+
| 'DISPUTE_FILE_UPLOAD'
262+
/**
263+
* Represents any file other than HTML.
264+
*
265+
* For example, after uploading the file, you can add the file to the
266+
* [Files page](https://shopify.com/admin/settings/files) in Shopify admin using the
267+
* [fileCreate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/fileCreate).
268+
*/
269+
| 'FILE'
270+
/**
271+
* An image.
272+
*
273+
* For example, after uploading an image, you can add the image to a product using the
274+
* [productCreateMedia mutation](https://shopify.dev/api/admin-graphql/latest/mutations/productCreateMedia)
275+
* or to the [Files page](https://shopify.com/admin/settings/files) in Shopify admin using the
276+
* [fileCreate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/fileCreate).
277+
*/
278+
| 'IMAGE'
279+
/**
280+
* A Shopify hosted 3d model.
281+
*
282+
* For example, after uploading the 3d model, you can add the 3d model to a product using the
283+
* [productCreateMedia mutation](https://shopify.dev/api/admin-graphql/latest/mutations/productCreateMedia).
284+
*/
285+
| 'MODEL_3D'
286+
/**
287+
* An image that's associated with a product.
288+
*
289+
* For example, after uploading the image, you can add the image to a product using the
290+
* [productCreateMedia mutation](https://shopify.dev/api/admin-graphql/latest/mutations/productCreateMedia).
291+
*/
292+
| 'PRODUCT_IMAGE'
293+
/**
294+
* Represents a label associated with a return.
295+
*
296+
* For example, once uploaded, this resource can be used to [create a
297+
* ReverseDelivery](https://shopify.dev/api/admin-graphql/unstable/mutations/reverseDeliveryCreateWithShipping).
298+
*/
299+
| 'RETURN_LABEL'
300+
/**
301+
* An image.
302+
*
303+
* For example, after uploading the image, you can add the image to the
304+
* [Files page](https://shopify.com/admin/settings/files) in Shopify admin using the
305+
* [fileCreate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/fileCreate).
306+
*/
307+
| 'SHOP_IMAGE'
308+
/**
309+
* Represents a redirect CSV file.
310+
*
311+
* Example usage: This resource can be used for creating a
312+
* [UrlRedirectImport](https://shopify.dev/api/admin-graphql/2022-04/objects/UrlRedirectImport)
313+
* object for use in the
314+
* [urlRedirectImportCreate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/urlRedirectImportCreate).
315+
*/
316+
| 'URL_REDIRECT_IMPORT'
317+
/**
318+
* A Shopify-hosted video.
319+
*
320+
* For example, after uploading the video, you can add the video to a product using the
321+
* [productCreateMedia mutation](https://shopify.dev/api/admin-graphql/latest/mutations/productCreateMedia)
322+
* or to the [Files page](https://shopify.com/admin/settings/files) in Shopify admin using the
323+
* [fileCreate mutation](https://shopify.dev/api/admin-graphql/latest/mutations/fileCreate).
324+
*/
325+
| 'VIDEO'

0 commit comments

Comments
 (0)