graphql-upload 8.0.3 → 8.0.7

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,47 @@
1
1
  # graphql-upload changelog
2
2
 
3
+ ## 8.0.7
4
+
5
+ ### Patch
6
+
7
+ - Updated dependencies.
8
+ - Handle invalid object paths in `map` multipart field entries, fixing [#154](https://github.com/jaydenseric/graphql-upload/issues/154).
9
+ - Import `WriteStream` from [`fs-capacitor`](https://npm.im/fs-capacitor) as a named rather than default import.
10
+
11
+ ## 8.0.6
12
+
13
+ ### Patch
14
+
15
+ - Updated dependencies.
16
+ - Allow batched operations again, fixing [#142](https://github.com/jaydenseric/graphql-upload/issues/142).
17
+ - Simplify tests by writing JSON as strings instead of using `JSON.stringify`.
18
+ - Use async middleware with [`express-async-handler`](https://npm.im/express-async-handler) for Express tests.
19
+ - Removed unintended `maxFiles` config in certain tests.
20
+ - Added the Open Graph image design to the logo Sketch file.
21
+
22
+ ## 8.0.5
23
+
24
+ ### Patch
25
+
26
+ - Updated dependencies.
27
+ - Handle invalid types in multipart fields and respond with meaningful HTTP 400 errors, via [#139](https://github.com/jaydenseric/graphql-upload/pull/139):
28
+ - Invalid `operations` type.
29
+ - Invalid `map` type.
30
+ - Invalid `map` entry type.
31
+ - Invalid `map` entry array item type.
32
+ - Additionally test current Node.js v8 and v10 versions with Travis.
33
+ - Reduced the size of the published `package.json` by moving dev tool config to files. This also prevents editor extensions such as Prettier and ESLint from detecting config and attempting to operate when opening package files installed in `node_modules`.
34
+ - Removed the [`watch`](https://npm.im/watch) dev dependency and `watch` script.
35
+ - Simplified the `prepublishOnly` script.
36
+ - Change to the `classic` TAP reporter for tests.
37
+ - Add [`apollo-server-koa`](https://npm.im/apollo-server-koa) and [`apollo-server-express`](https://npm.im/apollo-server-express) back to the compatible environments list in the readme, now that they use the current version of this package.
38
+
39
+ ## 8.0.4
40
+
41
+ ### Patch
42
+
43
+ - Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v2, fixing [#131](https://github.com/jaydenseric/graphql-upload/issues/131) via [#132](https://github.com/jaydenseric/graphql-upload/pull/132).
44
+
3
45
  ## 8.0.3
4
46
 
5
47
  ### Patch
@@ -7,7 +7,7 @@ var _util = _interopRequireDefault(require('util'))
7
7
 
8
8
  var _busboy = _interopRequireDefault(require('busboy'))
9
9
 
10
- var _fsCapacitor = _interopRequireDefault(require('fs-capacitor'))
10
+ var _fsCapacitor = require('fs-capacitor')
11
11
 
12
12
  var _httpErrors = _interopRequireDefault(require('http-errors'))
13
13
 
@@ -19,6 +19,15 @@ function _interopRequireDefault(obj) {
19
19
 
20
20
  const SPEC_URL = 'https://github.com/jaydenseric/graphql-multipart-request-spec'
21
21
 
22
+ const isObject = value => value && value.constructor === Object
23
+
24
+ const isString = value => typeof value === 'string' || value instanceof String
25
+
26
+ const ignoreStream = stream => {
27
+ stream.on('error', () => {})
28
+ stream.resume()
29
+ }
30
+
22
31
  class Upload {
23
32
  constructor() {
24
33
  this.promise = new Promise((resolve, reject) => {
@@ -80,13 +89,14 @@ const processRequest = (
80
89
  }
81
90
 
82
91
  parser.on('field', (fieldName, value) => {
92
+ if (exitError) return
93
+
83
94
  switch (fieldName) {
84
95
  case 'operations':
85
96
  try {
86
97
  operations = JSON.parse(value)
87
- operationsPath = (0, _objectPath.default)(operations)
88
98
  } catch (error) {
89
- exit(
99
+ return exit(
90
100
  (0, _httpErrors.default)(
91
101
  400,
92
102
  `Invalid JSON in the ‘operations’ multipart field (${SPEC_URL}).`
@@ -94,6 +104,14 @@ const processRequest = (
94
104
  )
95
105
  }
96
106
 
107
+ if (!isObject(operations) && !Array.isArray(operations))
108
+ return exit(
109
+ (0, _httpErrors.default)(
110
+ 400,
111
+ `Invalid type for the ‘operations’ multipart field (${SPEC_URL}).`
112
+ )
113
+ )
114
+ operationsPath = (0, _objectPath.default)(operations)
97
115
  break
98
116
 
99
117
  case 'map': {
@@ -104,10 +122,10 @@ const processRequest = (
104
122
  `Misordered multipart fields; ‘map’ should follow ‘operations’ (${SPEC_URL}).`
105
123
  )
106
124
  )
107
- let mapEntries
125
+ let parsedMap
108
126
 
109
127
  try {
110
- mapEntries = Object.entries(JSON.parse(value))
128
+ parsedMap = JSON.parse(value)
111
129
  } catch (error) {
112
130
  return exit(
113
131
  (0, _httpErrors.default)(
@@ -117,6 +135,14 @@ const processRequest = (
117
135
  )
118
136
  }
119
137
 
138
+ if (!isObject(parsedMap))
139
+ return exit(
140
+ (0, _httpErrors.default)(
141
+ 400,
142
+ `Invalid type for the ‘map’ multipart field (${SPEC_URL}).`
143
+ )
144
+ )
145
+ const mapEntries = Object.entries(parsedMap)
120
146
  if (mapEntries.length > maxFiles)
121
147
  return exit(
122
148
  (0, _httpErrors.default)(
@@ -127,10 +153,35 @@ const processRequest = (
127
153
  map = new Map()
128
154
 
129
155
  for (const [fieldName, paths] of mapEntries) {
156
+ if (!Array.isArray(paths))
157
+ return exit(
158
+ (0, _httpErrors.default)(
159
+ 400,
160
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${SPEC_URL}).`
161
+ )
162
+ )
130
163
  map.set(fieldName, new Upload())
131
164
 
132
- for (const path of paths)
133
- operationsPath.set(path, map.get(fieldName).promise)
165
+ for (const [index, path] of paths.entries()) {
166
+ if (!isString(path))
167
+ return exit(
168
+ (0, _httpErrors.default)(
169
+ 400,
170
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${SPEC_URL}).`
171
+ )
172
+ )
173
+
174
+ try {
175
+ operationsPath.set(path, map.get(fieldName).promise)
176
+ } catch (error) {
177
+ return exit(
178
+ (0, _httpErrors.default)(
179
+ 400,
180
+ `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${SPEC_URL}).`
181
+ )
182
+ )
183
+ }
184
+ }
134
185
  }
135
186
 
136
187
  resolve(operations)
@@ -138,9 +189,13 @@ const processRequest = (
138
189
  }
139
190
  })
140
191
  parser.on('file', (fieldName, stream, filename, encoding, mimetype) => {
192
+ if (exitError) {
193
+ ignoreStream(stream)
194
+ return
195
+ }
196
+
141
197
  if (!map) {
142
- stream.on('error', () => {})
143
- stream.resume()
198
+ ignoreStream(stream)
144
199
  return exit(
145
200
  (0, _httpErrors.default)(
146
201
  400,
@@ -155,54 +210,54 @@ const processRequest = (
155
210
  })
156
211
  const upload = map.get(fieldName)
157
212
 
158
- if (upload) {
159
- const capacitor = new _fsCapacitor.default()
160
- capacitor.on('error', () => {
161
- stream.unpipe()
162
- stream.resume()
163
- })
164
- stream.on('limit', () => {
165
- if (currentStream === stream) currentStream = null
166
- stream.unpipe()
167
- capacitor.destroy(
168
- (0, _httpErrors.default)(
169
- 413,
170
- 'File truncated as it exceeds the size limit.'
171
- )
213
+ if (!upload) {
214
+ ignoreStream(stream)
215
+ return
216
+ }
217
+
218
+ const capacitor = new _fsCapacitor.WriteStream()
219
+ capacitor.on('error', () => {
220
+ stream.unpipe()
221
+ stream.resume()
222
+ })
223
+ stream.on('limit', () => {
224
+ if (currentStream === stream) currentStream = null
225
+ stream.unpipe()
226
+ capacitor.destroy(
227
+ (0, _httpErrors.default)(
228
+ 413,
229
+ 'File truncated as it exceeds the size limit.'
172
230
  )
173
- })
174
- stream.on('error', error => {
175
- if (currentStream === stream) currentStream = null
176
- stream.unpipe()
177
- capacitor.destroy(exitError || error)
178
- })
179
- stream.pipe(capacitor)
180
- const file = {
181
- filename,
182
- mimetype,
183
- encoding,
184
-
185
- createReadStream() {
186
- const error = capacitor.error || (released ? exitError : null)
187
- if (error) throw error
188
- return capacitor.createReadStream()
189
- }
231
+ )
232
+ })
233
+ stream.on('error', error => {
234
+ if (currentStream === stream) currentStream = null
235
+ stream.unpipe()
236
+ capacitor.destroy(exitError || error)
237
+ })
238
+ stream.pipe(capacitor)
239
+ const file = {
240
+ filename,
241
+ mimetype,
242
+ encoding,
243
+
244
+ createReadStream() {
245
+ const error = capacitor.error || (released ? exitError : null)
246
+ if (error) throw error
247
+ return capacitor.createReadStream()
190
248
  }
191
- let capacitorStream
192
- Object.defineProperty(file, 'stream', {
193
- get: _util.default.deprecate(function() {
194
- if (!capacitorStream) capacitorStream = this.createReadStream()
195
- return capacitorStream
196
- }, 'File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.')
197
- })
198
- Object.defineProperty(file, 'capacitor', {
199
- value: capacitor
200
- })
201
- upload.resolve(file)
202
- } else {
203
- stream.on('error', () => {})
204
- stream.resume()
205
249
  }
250
+ let capacitorStream
251
+ Object.defineProperty(file, 'stream', {
252
+ get: _util.default.deprecate(function() {
253
+ if (!capacitorStream) capacitorStream = this.createReadStream()
254
+ return capacitorStream
255
+ }, 'File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.')
256
+ })
257
+ Object.defineProperty(file, 'capacitor', {
258
+ value: capacitor
259
+ })
260
+ upload.resolve(file)
206
261
  })
207
262
  parser.once('filesLimit', () =>
208
263
  exit(
@@ -1,10 +1,19 @@
1
1
  import util from 'util'
2
2
  import Busboy from 'busboy'
3
- import WriteStream from 'fs-capacitor'
3
+ import { WriteStream } from 'fs-capacitor'
4
4
  import createError from 'http-errors'
5
5
  import objectPath from 'object-path'
6
6
  const SPEC_URL = 'https://github.com/jaydenseric/graphql-multipart-request-spec'
7
7
 
8
+ const isObject = value => value && value.constructor === Object
9
+
10
+ const isString = value => typeof value === 'string' || value instanceof String
11
+
12
+ const ignoreStream = stream => {
13
+ stream.on('error', () => {})
14
+ stream.resume()
15
+ }
16
+
8
17
  class Upload {
9
18
  constructor() {
10
19
  this.promise = new Promise((resolve, reject) => {
@@ -66,13 +75,14 @@ export const processRequest = (
66
75
  }
67
76
 
68
77
  parser.on('field', (fieldName, value) => {
78
+ if (exitError) return
79
+
69
80
  switch (fieldName) {
70
81
  case 'operations':
71
82
  try {
72
83
  operations = JSON.parse(value)
73
- operationsPath = objectPath(operations)
74
84
  } catch (error) {
75
- exit(
85
+ return exit(
76
86
  createError(
77
87
  400,
78
88
  `Invalid JSON in the ‘operations’ multipart field (${SPEC_URL}).`
@@ -80,6 +90,14 @@ export const processRequest = (
80
90
  )
81
91
  }
82
92
 
93
+ if (!isObject(operations) && !Array.isArray(operations))
94
+ return exit(
95
+ createError(
96
+ 400,
97
+ `Invalid type for the ‘operations’ multipart field (${SPEC_URL}).`
98
+ )
99
+ )
100
+ operationsPath = objectPath(operations)
83
101
  break
84
102
 
85
103
  case 'map': {
@@ -90,10 +108,10 @@ export const processRequest = (
90
108
  `Misordered multipart fields; ‘map’ should follow ‘operations’ (${SPEC_URL}).`
91
109
  )
92
110
  )
93
- let mapEntries
111
+ let parsedMap
94
112
 
95
113
  try {
96
- mapEntries = Object.entries(JSON.parse(value))
114
+ parsedMap = JSON.parse(value)
97
115
  } catch (error) {
98
116
  return exit(
99
117
  createError(
@@ -103,6 +121,14 @@ export const processRequest = (
103
121
  )
104
122
  }
105
123
 
124
+ if (!isObject(parsedMap))
125
+ return exit(
126
+ createError(
127
+ 400,
128
+ `Invalid type for the ‘map’ multipart field (${SPEC_URL}).`
129
+ )
130
+ )
131
+ const mapEntries = Object.entries(parsedMap)
106
132
  if (mapEntries.length > maxFiles)
107
133
  return exit(
108
134
  createError(413, `${maxFiles} max file uploads exceeded.`)
@@ -110,10 +136,35 @@ export const processRequest = (
110
136
  map = new Map()
111
137
 
112
138
  for (const [fieldName, paths] of mapEntries) {
139
+ if (!Array.isArray(paths))
140
+ return exit(
141
+ createError(
142
+ 400,
143
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${SPEC_URL}).`
144
+ )
145
+ )
113
146
  map.set(fieldName, new Upload())
114
147
 
115
- for (const path of paths)
116
- operationsPath.set(path, map.get(fieldName).promise)
148
+ for (const [index, path] of paths.entries()) {
149
+ if (!isString(path))
150
+ return exit(
151
+ createError(
152
+ 400,
153
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${SPEC_URL}).`
154
+ )
155
+ )
156
+
157
+ try {
158
+ operationsPath.set(path, map.get(fieldName).promise)
159
+ } catch (error) {
160
+ return exit(
161
+ createError(
162
+ 400,
163
+ `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${SPEC_URL}).`
164
+ )
165
+ )
166
+ }
167
+ }
117
168
  }
118
169
 
119
170
  resolve(operations)
@@ -121,9 +172,13 @@ export const processRequest = (
121
172
  }
122
173
  })
123
174
  parser.on('file', (fieldName, stream, filename, encoding, mimetype) => {
175
+ if (exitError) {
176
+ ignoreStream(stream)
177
+ return
178
+ }
179
+
124
180
  if (!map) {
125
- stream.on('error', () => {})
126
- stream.resume()
181
+ ignoreStream(stream)
127
182
  return exit(
128
183
  createError(
129
184
  400,
@@ -138,51 +193,51 @@ export const processRequest = (
138
193
  })
139
194
  const upload = map.get(fieldName)
140
195
 
141
- if (upload) {
142
- const capacitor = new WriteStream()
143
- capacitor.on('error', () => {
144
- stream.unpipe()
145
- stream.resume()
146
- })
147
- stream.on('limit', () => {
148
- if (currentStream === stream) currentStream = null
149
- stream.unpipe()
150
- capacitor.destroy(
151
- createError(413, 'File truncated as it exceeds the size limit.')
152
- )
153
- })
154
- stream.on('error', error => {
155
- if (currentStream === stream) currentStream = null
156
- stream.unpipe()
157
- capacitor.destroy(exitError || error)
158
- })
159
- stream.pipe(capacitor)
160
- const file = {
161
- filename,
162
- mimetype,
163
- encoding,
164
-
165
- createReadStream() {
166
- const error = capacitor.error || (released ? exitError : null)
167
- if (error) throw error
168
- return capacitor.createReadStream()
169
- }
170
- }
171
- let capacitorStream
172
- Object.defineProperty(file, 'stream', {
173
- get: util.deprecate(function() {
174
- if (!capacitorStream) capacitorStream = this.createReadStream()
175
- return capacitorStream
176
- }, 'File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.')
177
- })
178
- Object.defineProperty(file, 'capacitor', {
179
- value: capacitor
180
- })
181
- upload.resolve(file)
182
- } else {
183
- stream.on('error', () => {})
196
+ if (!upload) {
197
+ ignoreStream(stream)
198
+ return
199
+ }
200
+
201
+ const capacitor = new WriteStream()
202
+ capacitor.on('error', () => {
203
+ stream.unpipe()
184
204
  stream.resume()
205
+ })
206
+ stream.on('limit', () => {
207
+ if (currentStream === stream) currentStream = null
208
+ stream.unpipe()
209
+ capacitor.destroy(
210
+ createError(413, 'File truncated as it exceeds the size limit.')
211
+ )
212
+ })
213
+ stream.on('error', error => {
214
+ if (currentStream === stream) currentStream = null
215
+ stream.unpipe()
216
+ capacitor.destroy(exitError || error)
217
+ })
218
+ stream.pipe(capacitor)
219
+ const file = {
220
+ filename,
221
+ mimetype,
222
+ encoding,
223
+
224
+ createReadStream() {
225
+ const error = capacitor.error || (released ? exitError : null)
226
+ if (error) throw error
227
+ return capacitor.createReadStream()
228
+ }
185
229
  }
230
+ let capacitorStream
231
+ Object.defineProperty(file, 'stream', {
232
+ get: util.deprecate(function() {
233
+ if (!capacitorStream) capacitorStream = this.createReadStream()
234
+ return capacitorStream
235
+ }, 'File upload property ‘stream’ is deprecated. Use ‘createReadStream()’ instead.')
236
+ })
237
+ Object.defineProperty(file, 'capacitor', {
238
+ value: capacitor
239
+ })
240
+ upload.resolve(file)
186
241
  })
187
242
  parser.once('filesLimit', () =>
188
243
  exit(createError(413, `${maxFiles} max file uploads exceeded.`))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-upload",
3
- "version": "8.0.3",
3
+ "version": "8.0.7",
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": {
@@ -36,34 +36,34 @@
36
36
  "graphql": "0.13.1 - 14"
37
37
  },
38
38
  "dependencies": {
39
- "busboy": "^0.3.0",
40
- "fs-capacitor": "^1.0.0",
41
- "http-errors": "^1.7.1",
39
+ "busboy": "^0.3.1",
40
+ "fs-capacitor": "^2.0.4",
41
+ "http-errors": "^1.7.2",
42
42
  "object-path": "^0.11.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/cli": "^7.2.3",
46
- "@babel/core": "^7.2.2",
47
- "@babel/preset-env": "^7.2.3",
45
+ "@babel/cli": "^7.4.4",
46
+ "@babel/core": "^7.4.5",
47
+ "@babel/preset-env": "^7.4.5",
48
48
  "babel-eslint": "^10.0.1",
49
- "eslint": "^5.12.0",
50
- "eslint-config-env": "^2.0.0",
51
- "eslint-config-prettier": "^3.3.0",
52
- "eslint-plugin-import": "^2.14.0",
53
- "eslint-plugin-import-order-alphabetical": "0.0.1",
54
- "eslint-plugin-node": "^8.0.1",
55
- "eslint-plugin-prettier": "^3.0.1",
56
- "express": "^4.16.4",
49
+ "eslint": "^5.16.0",
50
+ "eslint-config-env": "^6.0.0",
51
+ "eslint-config-prettier": "^4.3.0",
52
+ "eslint-plugin-import": "^2.17.3",
53
+ "eslint-plugin-import-order-alphabetical": "^0.0.2",
54
+ "eslint-plugin-node": "^9.1.0",
55
+ "eslint-plugin-prettier": "^3.1.0",
56
+ "express": "^4.17.1",
57
+ "express-async-handler": "^1.1.4",
57
58
  "form-data": "^2.3.3",
58
- "graphql": "^14.0.2",
59
- "husky": "^1.3.1",
60
- "jsdoc-md": "^1.7.0",
61
- "koa": "^2.6.2",
62
- "lint-staged": "^8.1.0",
63
- "node-fetch": "^2.3.0",
64
- "prettier": "^1.15.3",
65
- "tap": "^12.1.1",
66
- "watch": "^1.0.2"
59
+ "graphql": "^14.3.1",
60
+ "husky": "^2.4.1",
61
+ "jsdoc-md": "^3.0.0",
62
+ "koa": "^2.7.0",
63
+ "lint-staged": "^8.2.0",
64
+ "node-fetch": "^2.6.0",
65
+ "prettier": "^1.18.2",
66
+ "tap": "^14.2.2"
67
67
  },
68
68
  "scripts": {
69
69
  "prepare": "npm run prepare:clean && npm run prepare:mjs && npm run prepare:js && npm run prepare:jsdoc && npm run prepare:prettier",
@@ -75,32 +75,8 @@
75
75
  "test": "npm run test:eslint && npm run test:prettier && npm run test:mjs && npm run test:js",
76
76
  "test:eslint": "eslint . --ext mjs,js",
77
77
  "test:prettier": "prettier '**/*.{json,yml,md}' -l",
78
- "test:mjs": "node --experimental-modules --no-warnings lib/test | tap-mocha-reporter spec",
79
- "test:js": "node lib/test | tap-mocha-reporter spec",
80
- "prepublishOnly": "npm run prepare && npm test",
81
- "watch": "watch 'npm run prepublishOnly --silent' src --interval 1"
82
- },
83
- "husky": {
84
- "hooks": {
85
- "pre-commit": "lint-staged"
86
- }
87
- },
88
- "lint-staged": {
89
- "*.{mjs,js}": "eslint",
90
- "*.{json,yml,md}": "prettier -l"
91
- },
92
- "eslintIgnore": [
93
- "lib",
94
- "tap-snapshots"
95
- ],
96
- "eslintConfig": {
97
- "extends": [
98
- "env"
99
- ]
100
- },
101
- "prettier": {
102
- "proseWrap": "never",
103
- "singleQuote": true,
104
- "semi": false
78
+ "test:mjs": "node --experimental-modules --no-warnings lib/test | tap-mocha-reporter classic",
79
+ "test:js": "node lib/test | tap-mocha-reporter classic",
80
+ "prepublishOnly": "npm test"
105
81
  }
106
82
  }
package/readme.md CHANGED
@@ -17,14 +17,16 @@ The following environments are known to be compatible:
17
17
  - Native ESM with [`--experimental-modules`](https://nodejs.org/api/esm.html#esm_enabling)
18
18
  - [Koa](https://koajs.com)
19
19
  - [`graphql-api-koa`](https://npm.im/graphql-api-koa)
20
+ - [`apollo-server-koa`](https://npm.im/apollo-server-koa) (inbuilt)
20
21
  - [Express](https://expressjs.com)
21
22
  - [`express-graphql`](https://npm.im/express-graphql)
23
+ - [`apollo-server-express`](https://npm.im/apollo-server-express) (inbuilt)
22
24
 
23
25
  See also [GraphQL multipart request spec server implementations](https://github.com/jaydenseric/graphql-multipart-request-spec#server).
24
26
 
25
27
  ## Setup
26
28
 
27
- Setup is necessary if your environment doesn’t feature this package built in (see **_[Support](#support)_**).
29
+ Setup is necessary if your environment doesn’t feature this package inbuilt (see **_[Support](#support)_**).
28
30
 
29
31
  To install [`graphql-upload`](https://npm.im/graphql-upload) and the [`graphql`](https://npm.im/graphql) peer dependency from [npm](https://npmjs.com) run:
30
32
 
@@ -131,6 +133,8 @@ _A manually constructed schema with an image upload mutation._
131
133
  > })
132
134
  > ```
133
135
 
136
+ ---
137
+
134
138
  ### function graphqlUploadExpress
135
139
 
136
140
  Creates [Express](https://expressjs.com) middleware that processes GraphQL multipart requests using [`processRequest`](#function-processrequest), ignoring non-multipart requests. It sets the request body to be [similar to a conventional GraphQL POST request](#type-graphqloperation) for following GraphQL middleware to consume.
@@ -139,7 +143,7 @@ Creates [Express](https://expressjs.com) middleware that processes GraphQL multi
139
143
  | :-------- | :----------------------------------- | :---------------------- |
140
144
  | `options` | [UploadOptions](#type-uploadoptions) | GraphQL upload options. |
141
145
 
142
- **Returns:** [function](https://mdn.io/function) — Express middleware.
146
+ **Returns:** function — Express middleware.
143
147
 
144
148
  #### Examples
145
149
 
@@ -160,6 +164,8 @@ _Basic [`express-graphql`](https://npm.im/express-graphql) setup._
160
164
  > .listen(3000)
161
165
  > ```
162
166
 
167
+ ---
168
+
163
169
  ### function graphqlUploadKoa
164
170
 
165
171
  Creates [Koa](https://koajs.com) middleware that processes GraphQL multipart requests using [`processRequest`](#function-processrequest), ignoring non-multipart requests. It sets the request body to be [similar to a conventional GraphQL POST request](#type-graphqloperation) for following GraphQL middleware to consume.
@@ -168,7 +174,7 @@ Creates [Koa](https://koajs.com) middleware that processes GraphQL multipart req
168
174
  | :-------- | :----------------------------------- | :---------------------- |
169
175
  | `options` | [UploadOptions](#type-uploadoptions) | GraphQL upload options. |
170
176
 
171
- **Returns:** [function](https://mdn.io/function) — Koa middleware.
177
+ **Returns:** function — Koa middleware.
172
178
 
173
179
  #### Examples
174
180
 
@@ -189,17 +195,19 @@ _Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
189
195
  > .listen(3000)
190
196
  > ```
191
197
 
198
+ ---
199
+
192
200
  ### function processRequest
193
201
 
194
202
  Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). Used in [`graphqlUploadKoa`](#function-graphqluploadkoa) and [`graphqlUploadExpress`](#function-graphqluploadexpress) and can be used to create custom middleware.
195
203
 
196
- | Parameter | Type | Description |
197
- | :--------- | :------------------------------------ | :-------------------------------------------------------------------------------------------------------- |
198
- | `request` | IncomingMessage | [Node.js HTTP server request instance](https://nodejs.org/api/http.html#http_class_http_incomingmessage). |
199
- | `response` | ServerResponse | [Node.js HTTP server response instance](https://nodejs.org/api/http.html#http_class_http_serverresponse). |
200
- | `options` | [UploadOptions](#type-uploadoptions)? | GraphQL upload options. |
204
+ | Parameter | Type | Description |
205
+ | :-- | :-- | :-- |
206
+ | `request` | IncomingMessage | [Node.js HTTP server request instance](https://nodejs.org/api/http.html#http_class_http_incomingmessage). |
207
+ | `response` | ServerResponse | [Node.js HTTP server response instance](https://nodejs.org/api/http.html#http_class_http_serverresponse). |
208
+ | `options` | [UploadOptions](#type-uploadoptions)? | GraphQL upload options. |
201
209
 
202
- **Returns:** [Promise](https://mdn.io/promise)<[GraphQLOperation](#type-graphqloperation) | [Array](https://mdn.io/array)<[GraphQLOperation](#type-graphqloperation)>> — GraphQL operation or batch of operations for a GraphQL server to consume (usually as the request body).
210
+ **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).
203
211
 
204
212
  #### Examples
205
213
 
@@ -209,44 +217,50 @@ _How to import._
209
217
  > import { processRequest } from 'graphql-upload'
210
218
  > ```
211
219
 
220
+ ---
221
+
212
222
  ### type FileUpload
213
223
 
214
224
  File upload details, resolved from an [`Upload` scalar](#class-graphqlupload) promise.
215
225
 
216
- **Type:** [Object](https://mdn.io/object)
226
+ **Type:** Object
227
+
228
+ | Property | Type | Description |
229
+ | :-- | :-- | :-- |
230
+ | `filename` | string | File name. |
231
+ | `mimetype` | string | File MIME type. Provided by the client and can’t be trusted. |
232
+ | `encoding` | string | File stream transfer encoding. |
233
+ | `createReadStream` | function | Returns a Node.js readable stream of the file contents, for processing and storing the file. Multiple calls create independent streams. Throws if called after all resolvers have resolved, or after an error has interrupted the request. |
217
234
 
218
- | Property | Type | Description |
219
- | :----------------- | :---------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
220
- | `filename` | [string](https://mdn.io/string) | File name. |
221
- | `mimetype` | [string](https://mdn.io/string) | File MIME type. Provided by the client and can’t be trusted. |
222
- | `encoding` | [string](https://mdn.io/string) | File stream transfer encoding. |
223
- | `createReadStream` | [function](https://mdn.io/function) | Returns a Node.js readable stream of the file contents, for processing and storing the file. Multiple calls create independent streams. Throws if called after all resolvers have resolved, or after an error has interrupted the request. |
235
+ ---
224
236
 
225
237
  ### type GraphQLOperation
226
238
 
227
239
  A GraphQL operation object in a shape that can be consumed and executed by most GraphQL servers.
228
240
 
229
- **Type:** [Object](https://mdn.io/object)
241
+ **Type:** Object
230
242
 
231
- | Property | Type | Description |
232
- | :-------------- | :--------------------------------------- | :--------------------------------------------------- |
233
- | `query` | [string](https://mdn.io/string) | GraphQL document containing queries and fragments. |
234
- | `operationName` | [string](https://mdn.io/string) \| null? | GraphQL document operation name to execute. |
235
- | `variables` | [object](https://mdn.io/object) \| null? | GraphQL document operation variables and values map. |
243
+ | Property | Type | Description |
244
+ | :-- | :-- | :-- |
245
+ | `query` | string | GraphQL document containing queries and fragments. |
246
+ | `operationName` | string \| null? | GraphQL document operation name to execute. |
247
+ | `variables` | object \| null? | GraphQL document operation variables and values map. |
236
248
 
237
249
  #### See
238
250
 
239
251
  - [GraphQL over HTTP spec](https://github.com/APIs-guru/graphql-over-http#request-parameters).
240
252
  - [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests#postRequests).
241
253
 
254
+ ---
255
+
242
256
  ### type UploadOptions
243
257
 
244
258
  GraphQL upload server options, mostly relating to security, performance and limits.
245
259
 
246
- **Type:** [Object](https://mdn.io/object)
260
+ **Type:** Object
247
261
 
248
- | Property | Type | Description |
249
- | :------------- | :-------------------------------------------- | :------------------------------------------------------------------------------------ |
250
- | `maxFieldSize` | [number](https://mdn.io/number)? = `1000000` | Maximum allowed non-file multipart form field size in bytes; enough for your queries. |
251
- | `maxFileSize` | [number](https://mdn.io/number)? = `Infinity` | Maximum allowed file size in bytes. |
252
- | `maxFiles` | [number](https://mdn.io/number)? = `Infinity` | Maximum allowed number of files. |
262
+ | Property | Type | Description |
263
+ | :-- | :-- | :-- |
264
+ | `maxFieldSize` | number? = `1000000` | Maximum allowed non-file multipart form field size in bytes; enough for your queries. |
265
+ | `maxFileSize` | number? = `Infinity` | Maximum allowed file size in bytes. |
266
+ | `maxFiles` | number? = `Infinity` | Maximum allowed number of files. |