1
- import request from ' ./request' ;
2
- import { extractFiles } from ' extract-files' ;
3
- import { XHRResponse } from ' ../xhr/listeners' ;
1
+ import request from " ./request" ;
2
+ import { extractFiles } from " extract-files" ;
3
+ import { XHRResponse } from " ../xhr/listeners" ;
4
4
/*
5
5
Extract files is the official package used by the developer who helped
6
6
create the graphql upload spec in apollo client / server
@@ -9,7 +9,9 @@ import { XHRResponse } from '../xhr/listeners';
9
9
10
10
type GraphQLSetupOptions = {
11
11
baseUrl : string ;
12
- modifyRequest ?: ( request : GraphQLOptions ) => GraphQLOptions ;
12
+ modifyRequest ?: (
13
+ request : GraphQLOptions
14
+ ) => Promise < GraphQLOptions > | GraphQLOptions ;
13
15
} ;
14
16
15
17
export type GraphQLClientProps = {
@@ -39,26 +41,26 @@ type FileMap = {
39
41
export const createGraphQLClient = ( {
40
42
baseUrl,
41
43
modifyRequest,
42
- } : GraphQLSetupOptions ) => ( {
44
+ } : GraphQLSetupOptions ) => async ( {
43
45
onProgress,
44
46
options,
45
47
} : GraphQLClientProps ) : Promise < XHRResponse > => {
46
- let modifiedOptions = modifyRequest ? modifyRequest ( options ) : options ;
48
+ let modifiedOptions = modifyRequest ? await modifyRequest ( options ) : options ;
47
49
48
50
const { clone, files } = extractFiles ( {
49
51
query : options . mutation . loc . source . body ,
50
52
variables : options . variables ,
51
53
} ) ;
52
54
53
55
var body = new FormData ( ) ;
54
- body . append ( ' operations' , JSON . stringify ( clone ) ) ;
56
+ body . append ( " operations" , JSON . stringify ( clone ) ) ;
55
57
56
58
const map : FileMap = { } ;
57
59
let i = 0 ;
58
60
files . forEach ( ( paths : string ) => {
59
61
map [ ++ i ] = paths ;
60
62
} ) ;
61
- body . append ( ' map' , JSON . stringify ( map ) ) ;
63
+ body . append ( " map" , JSON . stringify ( map ) ) ;
62
64
63
65
i = 0 ;
64
66
files . forEach ( ( paths : string , file : File ) => {
@@ -69,6 +71,6 @@ export const createGraphQLClient = ({
69
71
body,
70
72
onProgress,
71
73
options : modifiedOptions ,
72
- url : `${ baseUrl } ${ options . path || '' } ` ,
74
+ url : `${ baseUrl } ${ options . path || "" } ` ,
73
75
} ) ;
74
76
} ;
0 commit comments