graphql-upload 11.0.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # graphql-upload changelog
2
2
 
3
+ ## 12.0.0
4
+
5
+ ### Major
6
+
7
+ - Updated Node.js support to `^12.20 || >= 14.13`.
8
+ - Updated dev dependencies, some of which require newer Node.js versions than previously supported.
9
+ - The tests are now ESM in `.mjs` files instead of CJS in `.js` files.
10
+ - Replaced the the `package.json` `exports` field public [subpath folder mapping](https://nodejs.org/api/packages.html#packages_subpath_folder_mappings) (deprecated by Node.js) with a [subpath pattern](https://nodejs.org/api/packages.html#packages_subpath_patterns). Deep `require` paths must now include the `.js` file extension.
11
+
12
+ ### Minor
13
+
14
+ - Added a package `sideEffects` field.
15
+
16
+ ### Patch
17
+
18
+ - Updated dependencies.
19
+ - Lint fixes for the updated Prettier version.
20
+ - Updated GitHub Actions CI config:
21
+ - Updated the tested Node.js versions to v12, v14, v16.
22
+ - Updated `actions/checkout` to v2.
23
+ - Updated `actions/setup-node` to v2.
24
+ - Simplify config with the [`npm install-test`](https://docs.npmjs.com/cli/v7/commands/npm-install-test) command.
25
+ - Don’t specify the `CI` environment variable as it’s set by default.
26
+ - Removed `npm-debug.log` from the `.gitignore` file as npm [v4.2.0](https://github.com/npm/npm/releases/tag/v4.2.0)+ doesn’t create it in the current working directory.
27
+ - Updated the EditorConfig URL.
28
+ - Updated the package `keywords` field.
29
+ - More specific package `main` field path.
30
+ - Simplified JSDoc related package scripts now that [`jsdoc-md`](https://npm.im/jsdoc-md) v10 automatically generates a Prettier formatted readme.
31
+ - Added a package `test:jsdoc` script that checks the readme API docs are up to date with the source JSDoc.
32
+ - Refactored private constants from exports of a single module to individual modules.
33
+ - Fixed test name and comment typos.
34
+ - Updated external URLs in docs.
35
+ - Prettier format for a JSDoc code example.
36
+ - Updated a `GraphQLUpload` code example to use [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema) instead of [`graphql-tools`](https://npm.im/graphql-tools).
37
+ - Removed from the readme the notice that the package was previously published as [`apollo-upload-server`](https://npm.im/apollo-upload-server).
38
+ - Simplified the readme “Setup” and “Support” sections.
39
+
3
40
  ## 11.0.0
4
41
 
5
42
  ### Major
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-upload",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -17,7 +17,9 @@
17
17
  "upload",
18
18
  "file",
19
19
  "multipart",
20
+ "request",
20
21
  "server",
22
+ "middleware",
21
23
  "koa",
22
24
  "express",
23
25
  "apollo",
@@ -28,56 +30,56 @@
28
30
  "private",
29
31
  "public"
30
32
  ],
31
- "main": "public",
33
+ "sideEffects": false,
34
+ "main": "./public/index.js",
32
35
  "exports": {
33
36
  ".": {
34
37
  "import": "./public/index.mjs",
35
38
  "require": "./public/index.js"
36
39
  },
37
- "./public/": "./public/",
40
+ "./public/*": "./public/*",
38
41
  "./package": "./package.json",
39
42
  "./package.json": "./package.json"
40
43
  },
41
44
  "engines": {
42
- "node": "^10.13.0 || ^12.0.0 || >= 13.7.0"
45
+ "node": "^12.20 || >= 14.13"
43
46
  },
44
47
  "peerDependencies": {
45
48
  "graphql": "0.13.1 - 15"
46
49
  },
47
50
  "dependencies": {
48
51
  "busboy": "^0.3.1",
49
- "fs-capacitor": "^6.1.0",
50
- "http-errors": "^1.7.3",
52
+ "fs-capacitor": "^6.2.0",
53
+ "http-errors": "^1.8.0",
51
54
  "isobject": "^4.0.0",
52
- "object-path": "^0.11.4"
55
+ "object-path": "^0.11.5"
53
56
  },
54
57
  "devDependencies": {
55
- "coverage-node": "^2.0.3",
56
- "eslint": "^7.1.0",
57
- "eslint-config-env": "^14.0.0",
58
- "eslint-config-prettier": "^6.11.0",
59
- "eslint-plugin-import": "^2.20.2",
60
- "eslint-plugin-jsdoc": "^25.4.2",
58
+ "coverage-node": "^5.0.1",
59
+ "eslint": "^7.25.0",
60
+ "eslint-config-env": "^19.0.2",
61
+ "eslint-config-prettier": "^8.3.0",
62
+ "eslint-plugin-import": "^2.22.1",
63
+ "eslint-plugin-jsdoc": "^33.1.0",
61
64
  "eslint-plugin-node": "^11.1.0",
62
- "eslint-plugin-prettier": "^3.1.3",
65
+ "eslint-plugin-prettier": "^3.4.0",
63
66
  "express": "^4.17.1",
64
- "form-data": "^3.0.0",
65
- "graphql": "^15.0.0",
67
+ "form-data": "^4.0.0",
68
+ "graphql": "^15.5.0",
66
69
  "hard-rejection": "^2.1.0",
67
- "jsdoc-md": "^6.0.0",
68
- "koa": "^2.12.0",
69
- "node-fetch": "^2.6.0",
70
- "prettier": "^2.0.5",
71
- "test-director": "^4.0.1"
70
+ "jsdoc-md": "^10.1.0",
71
+ "koa": "^2.13.1",
72
+ "node-fetch": "^2.6.1",
73
+ "prettier": "^2.2.1",
74
+ "test-director": "^6.0.0"
72
75
  },
73
76
  "scripts": {
74
- "prepare": "npm run prepare:jsdoc && npm run prepare:prettier",
75
- "prepare:jsdoc": "jsdoc-md",
76
- "prepare:prettier": "prettier --write readme.md",
77
- "test": "npm run test:eslint && npm run test:prettier && npm run test:api",
77
+ "jsdoc": "jsdoc-md",
78
+ "test": "npm run test:eslint && npm run test:prettier && npm run test:jsdoc && npm run test:api",
78
79
  "test:eslint": "eslint .",
79
80
  "test:prettier": "prettier -c .",
80
- "test:api": "coverage-node -r hard-rejection/register test",
81
+ "test:jsdoc": "jsdoc-md -c",
82
+ "test:api": "coverage-node -r hard-rejection/register test/index.mjs",
81
83
  "prepublishOnly": "npm test"
82
84
  }
83
85
  }
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Official [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec)
4
+ * [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec)
5
5
  * URL. Useful for error messages, etc.
6
6
  * @kind constant
7
- * @name SPEC_URL
7
+ * @name GRAPHQL_MULTIPART_REQUEST_SPEC_URL
8
8
  * @type {string}
9
9
  * @ignore
10
10
  */
11
- exports.SPEC_URL =
11
+ module.exports =
12
12
  'https://github.com/jaydenseric/graphql-multipart-request-spec';
@@ -1,3 +1,7 @@
1
+ // One of the JSDoc code examples contains `*/` escaped using `*\/`, see:
2
+ // https://github.com/gajus/eslint-plugin-jsdoc/issues/710
3
+ /* eslint-disable jsdoc/check-examples */
4
+
1
5
  'use strict';
2
6
 
3
7
  const { GraphQLScalarType, GraphQLError } = require('graphql');
@@ -24,11 +28,11 @@ const Upload = require('./Upload');
24
28
  * ```
25
29
  *
26
30
  * ```js
27
- * const GraphQLUpload = require('graphql-upload/public/GraphQLUpload');
31
+ * const GraphQLUpload = require('graphql-upload/public/GraphQLUpload.js');
28
32
  * ```
29
- * @example <caption>Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema).</caption>
33
+ * @example <caption>A schema built using [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema).</caption>
30
34
  * ```js
31
- * const { makeExecutableSchema } = require('graphql-tools');
35
+ * const { makeExecutableSchema } = require('@graphql-tools/schema');
32
36
  * const { GraphQLUpload } = require('graphql-upload');
33
37
  *
34
38
  * const schema = makeExecutableSchema({
@@ -42,11 +46,7 @@ const Upload = require('./Upload');
42
46
  * ```
43
47
  * @example <caption>A manually constructed schema with an image upload mutation.</caption>
44
48
  * ```js
45
- * const {
46
- * GraphQLSchema,
47
- * GraphQLObjectType,
48
- * GraphQLBoolean,
49
- * } = require('graphql');
49
+ * const { GraphQLSchema, GraphQLObjectType, GraphQLBoolean } = require('graphql');
50
50
  * const { GraphQLUpload } = require('graphql-upload');
51
51
  *
52
52
  * const schema = new GraphQLSchema({
package/public/Upload.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * The [`processRequest`]{@link processRequest} function places references to an
7
7
  * instance of this class wherever the file is expected in the
8
8
  * [GraphQL operation]{@link GraphQLOperation}. The
9
- * [`Upload` scalar]{@link GraphQLUpload} derives it’s value from the
9
+ * [`Upload`]{@link GraphQLUpload} scalar derives it’s value from the
10
10
  * [`promise`]{@link Upload#promise} property.
11
11
  * @kind class
12
12
  * @name Upload
@@ -24,7 +24,7 @@
24
24
  * ```
25
25
  *
26
26
  * ```js
27
- * const Upload = require('graphql-upload/public/Upload');
27
+ * const Upload = require('graphql-upload/public/Upload.js');
28
28
  * ```
29
29
  */
30
30
  module.exports = class Upload {
@@ -28,7 +28,7 @@ const defaultProcessRequest = require('./processRequest');
28
28
  * ```
29
29
  *
30
30
  * ```js
31
- * const graphqlUploadExpress = require('graphql-upload/public/graphqlUploadExpress');
31
+ * const graphqlUploadExpress = require('graphql-upload/public/graphqlUploadExpress.js');
32
32
  * ```
33
33
  * @example <caption>Basic [`express-graphql`](https://npm.im/express-graphql) setup.</caption>
34
34
  * ```js
@@ -28,7 +28,7 @@ const defaultProcessRequest = require('./processRequest');
28
28
  * ```
29
29
  *
30
30
  * ```js
31
- * const graphqlUploadKoa = require('graphql-upload/public/graphqlUploadKoa');
31
+ * const graphqlUploadKoa = require('graphql-upload/public/graphqlUploadKoa.js');
32
32
  * ```
33
33
  * @example <caption>Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup.</caption>
34
34
  * ```js
package/public/index.js CHANGED
@@ -20,7 +20,11 @@ exports.Upload = require('./Upload');
20
20
  */
21
21
 
22
22
  /**
23
- * Creates a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of an [uploading file’s]{@link FileUpload} contents, for processing and storage. Multiple calls create independent streams. Throws if called after all resolvers have resolved, or after an error has interrupted the request.
23
+ * Creates a
24
+ * [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams)
25
+ * of an [uploading file’s]{@link FileUpload} contents, for processing and
26
+ * storage. Multiple calls create independent streams. Throws if called after
27
+ * all resolvers have resolved, or after an error has interrupted the request.
24
28
  * @kind typedef
25
29
  * @name FileUploadCreateReadStream
26
30
  * @type {Function}
@@ -29,7 +33,7 @@ exports.Upload = require('./Upload');
29
33
  * @param {number} [options.highWaterMark=16384] Maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
30
34
  * @returns {Readable} [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of the file’s contents.
31
35
  * @see [Node.js `Readable` stream constructor docs](https://nodejs.org/api/stream.html#stream_new_stream_readable_options).
32
- * @see [Node.js stream backpressure guide](https://nodejs.org/es/docs/guides/backpressuring-in-streams).
36
+ * @see [Node.js stream backpressure guide](https://nodejs.org/en/docs/guides/backpressuring-in-streams).
33
37
  */
34
38
 
35
39
  /**
@@ -41,12 +45,13 @@ exports.Upload = require('./Upload');
41
45
  * @prop {string} query GraphQL document containing queries and fragments.
42
46
  * @prop {string|null} [operationName] GraphQL document operation name to execute.
43
47
  * @prop {object|null} [variables] GraphQL document operation variables and values map.
44
- * @see [GraphQL over HTTP spec](https://github.com/APIs-guru/graphql-over-http#request-parameters).
45
- * @see [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests#postRequests).
48
+ * @see [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http).
49
+ * @see [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests/#post-requests).
46
50
  */
47
51
 
48
52
  /**
49
- * Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
53
+ * Processes a
54
+ * [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
50
55
  * @kind typedef
51
56
  * @name ProcessRequestFunction
52
57
  * @type {Function}
@@ -58,7 +63,8 @@ exports.Upload = require('./Upload');
58
63
  */
59
64
 
60
65
  /**
61
- * Options for processing a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec);
66
+ * Options for processing a
67
+ * [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec);
62
68
  * mostly relating to security, performance and limits.
63
69
  * @kind typedef
64
70
  * @name ProcessRequestOptions
@@ -5,22 +5,23 @@ const { WriteStream } = require('fs-capacitor');
5
5
  const createError = require('http-errors');
6
6
  const isObject = require('isobject');
7
7
  const objectPath = require('object-path');
8
- const { SPEC_URL } = require('../private/constants');
8
+ const GRAPHQL_MULTIPART_REQUEST_SPEC_URL = require('../private/GRAPHQL_MULTIPART_REQUEST_SPEC_URL');
9
9
  const ignoreStream = require('../private/ignoreStream');
10
10
  const Upload = require('./Upload');
11
11
 
12
12
  /**
13
- * Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
13
+ * Processes a
14
+ * [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
14
15
  * It parses the `operations` and `map` fields to create an
15
16
  * [`Upload`]{@link Upload} instance for each expected file upload, placing
16
17
  * references wherever the file is expected in the
17
18
  * [GraphQL operation]{@link GraphQLOperation} for the
18
- * [`Upload` scalar]{@link GraphQLUpload} to derive it’s value. Errors are
19
- * created with [`http-errors`](https://npm.im/http-errors) to assist in
20
- * sending responses with appropriate HTTP status codes. Used in
19
+ * [`Upload`]{@link GraphQLUpload} scalar to derive it’s value. Errors are
20
+ * created with [`http-errors`](https://npm.im/http-errors) to assist in sending
21
+ * responses with appropriate HTTP status codes. Used in
21
22
  * [`graphqlUploadExpress`]{@link graphqlUploadExpress} and
22
- * [`graphqlUploadKoa`]{@link graphqlUploadKoa} and can be used to create
23
- * custom middleware.
23
+ * [`graphqlUploadKoa`]{@link graphqlUploadKoa} and can be used to create custom
24
+ * middleware.
24
25
  * @kind function
25
26
  * @name processRequest
26
27
  * @type {ProcessRequestFunction}
@@ -38,7 +39,7 @@ const Upload = require('./Upload');
38
39
  * ```
39
40
  *
40
41
  * ```js
41
- * const processRequest = require('graphql-upload/public/processRequest');
42
+ * const processRequest = require('graphql-upload/public/processRequest.js');
42
43
  * ```
43
44
  */
44
45
  module.exports = function processRequest(
@@ -152,7 +153,7 @@ module.exports = function processRequest(
152
153
  return exit(
153
154
  createError(
154
155
  400,
155
- `Invalid JSON in the ‘operations’ multipart field (${SPEC_URL}).`
156
+ `Invalid JSON in the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
156
157
  )
157
158
  );
158
159
  }
@@ -161,7 +162,7 @@ module.exports = function processRequest(
161
162
  return exit(
162
163
  createError(
163
164
  400,
164
- `Invalid type for the ‘operations’ multipart field (${SPEC_URL}).`
165
+ `Invalid type for the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
165
166
  )
166
167
  );
167
168
 
@@ -173,7 +174,7 @@ module.exports = function processRequest(
173
174
  return exit(
174
175
  createError(
175
176
  400,
176
- `Misordered multipart fields; ‘map’ should follow ‘operations’ (${SPEC_URL}).`
177
+ `Misordered multipart fields; ‘map’ should follow ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
177
178
  )
178
179
  );
179
180
 
@@ -184,7 +185,7 @@ module.exports = function processRequest(
184
185
  return exit(
185
186
  createError(
186
187
  400,
187
- `Invalid JSON in the ‘map’ multipart field (${SPEC_URL}).`
188
+ `Invalid JSON in the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
188
189
  )
189
190
  );
190
191
  }
@@ -193,14 +194,14 @@ module.exports = function processRequest(
193
194
  return exit(
194
195
  createError(
195
196
  400,
196
- `Invalid type for the ‘map’ multipart field (${SPEC_URL}).`
197
+ `Invalid type for the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
197
198
  )
198
199
  );
199
200
 
200
201
  const mapEntries = Object.entries(parsedMap);
201
202
 
202
- // Check max files is not exceeded, even though the number of files to
203
- // parse might not match th(e map provided by the client.
203
+ // Check max files is not exceeded, even though the number of files
204
+ // to parse might not match the map provided by the client.
204
205
  if (mapEntries.length > maxFiles)
205
206
  return exit(
206
207
  createError(413, `${maxFiles} max file uploads exceeded.`)
@@ -212,7 +213,7 @@ module.exports = function processRequest(
212
213
  return exit(
213
214
  createError(
214
215
  400,
215
- `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${SPEC_URL}).`
216
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
216
217
  )
217
218
  );
218
219
 
@@ -223,7 +224,7 @@ module.exports = function processRequest(
223
224
  return exit(
224
225
  createError(
225
226
  400,
226
- `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${SPEC_URL}).`
227
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
227
228
  )
228
229
  );
229
230
 
@@ -233,7 +234,7 @@ module.exports = function processRequest(
233
234
  return exit(
234
235
  createError(
235
236
  400,
236
- `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${SPEC_URL}).`
237
+ `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
237
238
  )
238
239
  );
239
240
  }
@@ -257,7 +258,7 @@ module.exports = function processRequest(
257
258
  return exit(
258
259
  createError(
259
260
  400,
260
- `Misordered multipart fields; files should follow ‘map’ (${SPEC_URL}).`
261
+ `Misordered multipart fields; files should follow ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
261
262
  )
262
263
  );
263
264
  }
@@ -328,13 +329,16 @@ module.exports = function processRequest(
328
329
  return exit(
329
330
  createError(
330
331
  400,
331
- `Missing multipart field ‘operations’ (${SPEC_URL}).`
332
+ `Missing multipart field ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
332
333
  )
333
334
  );
334
335
 
335
336
  if (!map)
336
337
  return exit(
337
- createError(400, `Missing multipart field ‘map’ (${SPEC_URL}).`)
338
+ createError(
339
+ 400,
340
+ `Missing multipart field ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
341
+ )
338
342
  );
339
343
 
340
344
  for (const upload of map.values())
package/readme.md CHANGED
@@ -4,42 +4,25 @@
4
4
 
5
5
  [![npm version](https://badgen.net/npm/v/graphql-upload)](https://npm.im/graphql-upload) [![CI status](https://github.com/jaydenseric/graphql-upload/workflows/CI/badge.svg)](https://github.com/jaydenseric/graphql-upload/actions)
6
6
 
7
- Middleware and an [`Upload` scalar](#class-graphqlupload) to add support for [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec) (file uploads via queries and mutations) to various Node.js GraphQL servers.
8
-
9
- ⚠️ Previously published as [`apollo-upload-server`](https://npm.im/apollo-upload-server).
10
-
11
- ## Support
12
-
13
- The following environments are known to be compatible:
14
-
15
- - [Node.js](https://nodejs.org) `^10.13.0 || ^12.0.0 || >= 13.7.0`
16
- - [Koa](https://koajs.com)
17
- - [`graphql-api-koa`](https://npm.im/graphql-api-koa)
18
- - [`koa-graphql`](https://npm.im/koa-graphql)
19
- - [`apollo-server-koa`](https://npm.im/apollo-server-koa) (inbuilt)
20
- - [Express](https://expressjs.com)
21
- - [`express-graphql`](https://npm.im/express-graphql)
22
- - [`apollo-server-express`](https://npm.im/apollo-server-express) (inbuilt)
23
-
24
- See also [GraphQL multipart request spec server implementations](https://github.com/jaydenseric/graphql-multipart-request-spec#server).
7
+ Middleware and an [`Upload`](#class-graphqlupload) scalar to add support for [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec) (file uploads via queries and mutations) to various Node.js GraphQL servers.
25
8
 
26
9
  ## Setup
27
10
 
28
- Setup is necessary if your environment doesn’t feature this package inbuilt (see **_[Support](#support)_**).
11
+ First, check if there are [GraphQL multipart request spec server implementations](https://github.com/jaydenseric/graphql-multipart-request-spec#server) (most for Node.js integrate [`graphql-upload`](https://npm.im/graphql-upload)) that are more suitable for your environment than a manual setup.
29
12
 
30
- To install [`graphql-upload`](https://npm.im/graphql-upload) and the [`graphql`](https://npm.im/graphql) peer dependency from [npm](https://npmjs.com) run:
13
+ To install [`graphql-upload`](https://npm.im/graphql-upload) and the [`graphql`](https://npm.im/graphql) peer dependency with [npm](https://npmjs.com/get-npm), run:
31
14
 
32
- ```shell
15
+ ```sh
33
16
  npm install graphql-upload graphql
34
17
  ```
35
18
 
36
19
  Use the [`graphqlUploadKoa`](#function-graphqluploadkoa) or [`graphqlUploadExpress`](#function-graphqluploadexpress) middleware just before GraphQL middleware. Alternatively, use [`processRequest`](#function-processrequest) to create custom middleware.
37
20
 
38
- A schema built with separate SDL and resolvers (e.g. using [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema)) requires the [`Upload` scalar](#class-graphqlupload) to be setup.
21
+ A schema built with separate SDL and resolvers (e.g. using [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema)) requires the [`Upload`](#class-graphqlupload) scalar to be setup.
39
22
 
40
23
  ## Usage
41
24
 
42
- [Clients implementing the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec#client) upload files as [`Upload` scalar](#class-graphqlupload) query or mutation variables. Their resolver values are promises that resolve [file upload details](#type-fileupload) for processing and storage. Files are typically streamed into cloud storage but may also be stored in the filesystem.
25
+ [Clients implementing the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec#client) upload files as [`Upload`](#class-graphqlupload) scalar query or mutation variables. Their resolver values are promises that resolve [file upload details](#type-fileupload) for processing and storage. Files are typically streamed into cloud storage but may also be stored in the filesystem.
43
26
 
44
27
  See the [example API and client](https://github.com/jaydenseric/apollo-upload-examples).
45
28
 
@@ -57,10 +40,14 @@ See the [example API and client](https://github.com/jaydenseric/apollo-upload-ex
57
40
 
58
41
  The [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec) allows a file to be used for multiple query or mutation variables (file deduplication), and for variables to be used in multiple places. GraphQL resolvers need to be able to manage independent file streams. As resolvers are executed asynchronously, it’s possible they will try to process files in a different order than received in the multipart request.
59
42
 
60
- [`busboy`](https://npm.im/busboy) parses multipart request streams. Once the `operations` and `map` fields have been parsed, [`Upload` scalar](#class-graphqlupload) values in the GraphQL operations are populated with promises, and the operations are passed down the middleware chain to GraphQL resolvers.
43
+ [`busboy`](https://npm.im/busboy) parses multipart request streams. Once the `operations` and `map` fields have been parsed, [`Upload`](#class-graphqlupload) scalar values in the GraphQL operations are populated with promises, and the operations are passed down the middleware chain to GraphQL resolvers.
61
44
 
62
45
  [`fs-capacitor`](https://npm.im/fs-capacitor) is used to buffer file uploads to the filesystem and coordinate simultaneous reading and writing. As soon as a file upload’s contents begins streaming, its data begins buffering to the filesystem and its associated promise resolves. GraphQL resolvers can then create new streams from the buffer by calling [`createReadStream()`](#type-fileupload). The buffer is destroyed once all streams have ended or closed and the server has responded to the request. Any remaining buffer files will be cleaned when the process exits.
63
46
 
47
+ ## Support
48
+
49
+ - [Node.js](https://nodejs.org): `^12.20 || >= 14.13`
50
+
64
51
  ## API
65
52
 
66
53
  ### Table of contents
@@ -103,13 +90,13 @@ _Ways to `require`._
103
90
  > ```
104
91
  >
105
92
  > ```js
106
- > const GraphQLUpload = require('graphql-upload/public/GraphQLUpload');
93
+ > const GraphQLUpload = require('graphql-upload/public/GraphQLUpload.js');
107
94
  > ```
108
95
 
109
- _Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema)._
96
+ _A schema built using [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema)._
110
97
 
111
98
  > ```js
112
- > const { makeExecutableSchema } = require('graphql-tools');
99
+ > const { makeExecutableSchema } = require('@graphql-tools/schema');
113
100
  > const { GraphQLUpload } = require('graphql-upload');
114
101
  >
115
102
  > const schema = makeExecutableSchema({
@@ -161,7 +148,7 @@ _A manually constructed schema with an image upload mutation._
161
148
 
162
149
  ### class Upload
163
150
 
164
- A file expected to be uploaded as it has been declared in the `map` field of a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). The [`processRequest`](#function-processrequest) function places references to an instance of this class wherever the file is expected in the [GraphQL operation](#type-graphqloperation). The [`Upload` scalar](#class-graphqlupload) derives it’s value from the [`promise`](#upload-instance-property-promise) property.
151
+ A file expected to be uploaded as it has been declared in the `map` field of a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). The [`processRequest`](#function-processrequest) function places references to an instance of this class wherever the file is expected in the [GraphQL operation](#type-graphqloperation). The [`Upload`](#class-graphqlupload) scalar derives it’s value from the [`promise`](#upload-instance-property-promise) property.
165
152
 
166
153
  #### Examples
167
154
 
@@ -182,7 +169,7 @@ _Ways to `require`._
182
169
  > ```
183
170
  >
184
171
  > ```js
185
- > const Upload = require('graphql-upload/public/Upload');
172
+ > const Upload = require('graphql-upload/public/Upload.js');
186
173
  > ```
187
174
 
188
175
  #### Upload instance method reject
@@ -211,7 +198,7 @@ The file upload details, available when the [upload promise](#upload-instance-pr
211
198
 
212
199
  Promise that resolves file upload details. This should only be utilized by [`GraphQLUpload`](#class-graphqlupload).
213
200
 
214
- **Type:** Promise&lt;[FileUpload](#type-fileupload)>
201
+ **Type:** Promise<[FileUpload](#type-fileupload)>
215
202
 
216
203
  ---
217
204
 
@@ -245,7 +232,7 @@ _Ways to `require`._
245
232
  > ```
246
233
  >
247
234
  > ```js
248
- > const graphqlUploadExpress = require('graphql-upload/public/graphqlUploadExpress');
235
+ > const graphqlUploadExpress = require('graphql-upload/public/graphqlUploadExpress.js');
249
236
  > ```
250
237
 
251
238
  _Basic [`express-graphql`](https://npm.im/express-graphql) setup._
@@ -297,7 +284,7 @@ _Ways to `require`._
297
284
  > ```
298
285
  >
299
286
  > ```js
300
- > const graphqlUploadKoa = require('graphql-upload/public/graphqlUploadKoa');
287
+ > const graphqlUploadKoa = require('graphql-upload/public/graphqlUploadKoa.js');
301
288
  > ```
302
289
 
303
290
  _Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
@@ -321,7 +308,7 @@ _Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
321
308
 
322
309
  ### function processRequest
323
310
 
324
- Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). It parses the `operations` and `map` fields to create an [`Upload`](#class-upload) instance for each expected file upload, placing references wherever the file is expected in the [GraphQL operation](#type-graphqloperation) for the [`Upload` scalar](#class-graphqlupload) to derive it’s value. Errors are created with [`http-errors`](https://npm.im/http-errors) to assist in sending responses with appropriate HTTP status codes. Used in [`graphqlUploadExpress`](#function-graphqluploadexpress) and [`graphqlUploadKoa`](#function-graphqluploadkoa) and can be used to create custom middleware.
311
+ Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). It parses the `operations` and `map` fields to create an [`Upload`](#class-upload) instance for each expected file upload, placing references wherever the file is expected in the [GraphQL operation](#type-graphqloperation) for the [`Upload`](#class-graphqlupload) scalar to derive it’s value. Errors are created with [`http-errors`](https://npm.im/http-errors) to assist in sending responses with appropriate HTTP status codes. Used in [`graphqlUploadExpress`](#function-graphqluploadexpress) and [`graphqlUploadKoa`](#function-graphqluploadkoa) and can be used to create custom middleware.
325
312
 
326
313
  **Type:** [ProcessRequestFunction](#type-processrequestfunction)
327
314
 
@@ -344,7 +331,7 @@ _Ways to `require`._
344
331
  > ```
345
332
  >
346
333
  > ```js
347
- > const processRequest = require('graphql-upload/public/processRequest');
334
+ > const processRequest = require('graphql-upload/public/processRequest.js');
348
335
  > ```
349
336
 
350
337
  ---
@@ -381,7 +368,7 @@ Creates a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_re
381
368
  #### See
382
369
 
383
370
  - [Node.js `Readable` stream constructor docs](https://nodejs.org/api/stream.html#stream_new_stream_readable_options).
384
- - [Node.js stream backpressure guide](https://nodejs.org/es/docs/guides/backpressuring-in-streams).
371
+ - [Node.js stream backpressure guide](https://nodejs.org/en/docs/guides/backpressuring-in-streams).
385
372
 
386
373
  ---
387
374
 
@@ -399,8 +386,8 @@ A GraphQL operation object in a shape that can be consumed and executed by most
399
386
 
400
387
  #### See
401
388
 
402
- - [GraphQL over HTTP spec](https://github.com/APIs-guru/graphql-over-http#request-parameters).
403
- - [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests#postRequests).
389
+ - [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http).
390
+ - [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests/#post-requests).
404
391
 
405
392
  ---
406
393
 
@@ -416,7 +403,7 @@ Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-m
416
403
  | `response` | ServerResponse | [Node.js HTTP server response instance](https://nodejs.org/api/http.html#http_class_http_serverresponse). |
417
404
  | `options` | [ProcessRequestOptions](#type-processrequestoptions)? | Options for processing the request. |
418
405
 
419
- **Returns:** Promise&lt;[GraphQLOperation](#type-graphqloperation) | Array&lt;[GraphQLOperation](#type-graphqloperation)>> — GraphQL operation or batch of operations for a GraphQL server to consume (usually as the request body).
406
+ **Returns:** Promise<[GraphQLOperation](#type-graphqloperation) | Array<[GraphQLOperation](#type-graphqloperation)>> — GraphQL operation or batch of operations for a GraphQL server to consume (usually as the request body).
420
407
 
421
408
  #### See
422
409