Skip to content

Commit c0bfb40

Browse files
committed
Let modify options be async
1 parent 1eb44b1 commit c0bfb40

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-use-upload",
3-
"version": "0.5.11",
3+
"version": "0.5.13-beta",
44
"description": "",
55
"main": "cjs/index.js",
66
"module": "lib/index.js",

src/clients/graphql/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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";
44
/*
55
Extract files is the official package used by the developer who helped
66
create the graphql upload spec in apollo client / server
@@ -9,7 +9,9 @@ import { XHRResponse } from '../xhr/listeners';
99

1010
type GraphQLSetupOptions = {
1111
baseUrl: string;
12-
modifyRequest?: (request: GraphQLOptions) => GraphQLOptions;
12+
modifyRequest?: (
13+
request: GraphQLOptions
14+
) => Promise<GraphQLOptions> | GraphQLOptions;
1315
};
1416

1517
export type GraphQLClientProps = {
@@ -39,26 +41,26 @@ type FileMap = {
3941
export const createGraphQLClient = ({
4042
baseUrl,
4143
modifyRequest,
42-
}: GraphQLSetupOptions) => ({
44+
}: GraphQLSetupOptions) => async ({
4345
onProgress,
4446
options,
4547
}: GraphQLClientProps): Promise<XHRResponse> => {
46-
let modifiedOptions = modifyRequest ? modifyRequest(options) : options;
48+
let modifiedOptions = modifyRequest ? await modifyRequest(options) : options;
4749

4850
const { clone, files } = extractFiles({
4951
query: options.mutation.loc.source.body,
5052
variables: options.variables,
5153
});
5254

5355
var body = new FormData();
54-
body.append('operations', JSON.stringify(clone));
56+
body.append("operations", JSON.stringify(clone));
5557

5658
const map: FileMap = {};
5759
let i = 0;
5860
files.forEach((paths: string) => {
5961
map[++i] = paths;
6062
});
61-
body.append('map', JSON.stringify(map));
63+
body.append("map", JSON.stringify(map));
6264

6365
i = 0;
6466
files.forEach((paths: string, file: File) => {
@@ -69,6 +71,6 @@ export const createGraphQLClient = ({
6971
body,
7072
onProgress,
7173
options: modifiedOptions,
72-
url: `${baseUrl}${options.path || ''}`,
74+
url: `${baseUrl}${options.path || ""}`,
7375
});
7476
};

src/clients/xhr/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type XHRClient = (args: XHRClientProps) => Promise<XHRResponse>;
1414

1515
export type XHRSetupOptions = {
1616
baseUrl?: string;
17-
modifyRequest?: (request: XHROptions) => XHROptions;
17+
modifyRequest?: (request: XHROptions) => Promise<XHROptions> | XHROptions;
1818
};
1919

2020
export type GetUrlResponse =
@@ -48,7 +48,7 @@ export const createXhrClient = ({
4848
files,
4949
options,
5050
}: XHRClientProps): Promise<XHRResponse> => {
51-
let modifiedOptions = modifyRequest ? modifyRequest(options) : options;
51+
let modifiedOptions = modifyRequest ? await modifyRequest(options) : options;
5252
let url = `${baseUrl || ""}${options.path || ""}`;
5353

5454
//Get the url using a promise, for signed uploads

0 commit comments

Comments
 (0)