File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,13 @@ export abstract class RequestUploadOutput {
23
23
@InputType ( )
24
24
export abstract class CreateDefinedFileVersionInput {
25
25
@IdField ( {
26
- description : 'The ID returned from the `requestFileUpload` mutation' ,
26
+ description : stripIndent `
27
+ The ID returned from the \`requestFileUpload\` mutation.
28
+ This _can_ be skipped if \`file\` is provided.
29
+ ` ,
30
+ nullable : true ,
27
31
} )
28
- readonly uploadId : ID ;
32
+ readonly uploadId ? : ID ;
29
33
30
34
@Field ( ( ) => UploadScalar , {
31
35
description : stripIndent `
Original file line number Diff line number Diff line change @@ -262,10 +262,15 @@ export class FileService {
262
262
const {
263
263
parentId,
264
264
file : uploadingFile ,
265
- uploadId,
265
+ uploadId : uploadIdInput ,
266
266
mimeType : mimeTypeOverride ,
267
267
media,
268
268
} = input ;
269
+ if ( ! uploadIdInput && ! uploadingFile ) {
270
+ throw new InputException ( 'Upload ID is required' , 'uploadId' ) ;
271
+ }
272
+
273
+ const uploadId = uploadIdInput ?? ( await generateId ( ) ) ;
269
274
270
275
const parentType = await this . validateParentNode (
271
276
parentId ,
@@ -274,12 +279,14 @@ export class FileService {
274
279
) ;
275
280
276
281
if ( uploadingFile ) {
277
- const prevExists = await this . bucket . headObject ( uploadId ) . catch ( ( e ) => {
278
- if ( e instanceof NotFoundException ) {
279
- return false ;
280
- }
281
- throw e ;
282
- } ) ;
282
+ const prevExists = uploadIdInput
283
+ ? await this . bucket . headObject ( uploadId ) . catch ( ( e ) => {
284
+ if ( e instanceof NotFoundException ) {
285
+ return false ;
286
+ }
287
+ throw e ;
288
+ } )
289
+ : false ;
283
290
if ( prevExists ) {
284
291
throw new InputException (
285
292
'A file with this ID already exists. Request an new upload ID.' ,
You can’t perform that action at this time.
0 commit comments