Skip to content

Commit c9dd85f

Browse files
committed
Fix
1 parent 448a123 commit c9dd85f

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/links/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
},
5353
"dependencies": {
5454
"@graphql-tools/utils": "^10.11.0",
55+
"@whatwg-node/fetch": "^0.10.13",
5556
"apollo-upload-client": "^19.0.0",
5657
"tslib": "^2.4.0"
5758
},

packages/links/src/AwaitVariablesLink.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Readable } from 'stream';
22
import * as apolloImport from '@apollo/client';
33
import { mapMaybePromise } from '@graphql-tools/utils';
4+
import { File } from '@whatwg-node/fetch';
45

56
const apollo: typeof apolloImport = (apolloImport as any)?.default ?? apolloImport;
67

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
import isExtractableFile from 'apollo-upload-client/isExtractableFile.mjs';
12
import UploadHttpLink from 'apollo-upload-client/UploadHttpLink.mjs';
23
import * as apolloImport from '@apollo/client';
4+
import { fetch, File, FormData } from '@whatwg-node/fetch';
35
import { AwaitVariablesLink } from './AwaitVariablesLink.js';
46

57
const apollo: typeof apolloImport = (apolloImport as any)?.default ?? apolloImport;
68

79
export const createServerHttpLink = (options: any) =>
8-
apollo.concat(new AwaitVariablesLink(), new UploadHttpLink(options) as any);
10+
apollo.concat(
11+
new AwaitVariablesLink(),
12+
new UploadHttpLink({
13+
...options,
14+
isExtractableFile: v =>
15+
isExtractableFile(v) || v instanceof File || options?.isExtractableFile?.(v),
16+
fetch: options?.fetch ?? fetch,
17+
FormData: options?.FormData ?? FormData,
18+
}) as any,
19+
);

packages/links/tests/upload.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { Server } from 'http';
22
import { AddressInfo } from 'net';
33
import { Readable } from 'stream';
44
import express, { Express } from 'express';
5-
import FormData from 'form-data';
65
import { buildSchema, GraphQLSchema, parse } from 'graphql';
76
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
87
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
9-
import fetch from 'node-fetch';
108
import { execute } from '@graphql-tools/executor';
119
import { makeExecutableSchema } from '@graphql-tools/schema';
1210
import { stitchSchemas } from '@graphql-tools/stitch';
11+
import { fetch, File, FormData } from '@whatwg-node/fetch';
1312
import { describeIf } from '../../../packages/testing/utils.js';
1413
import {
1514
createServerHttpLink,
@@ -51,7 +50,8 @@ function testGraphqlMultipartRequest(query: string, port: number) {
5150
}),
5251
);
5352
body.append('map', '{ "1": ["variables.file"] }');
54-
body.append('1', 'abc', { filename: __filename });
53+
const file = new File(['abc'], __filename);
54+
body.append('1', file);
5555

5656
return fetch(`http://localhost:${port.toString()}`, {
5757
method: 'POST',

0 commit comments

Comments
 (0)