graphql-upload 8.0.7 → 11.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/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # graphql-upload
4
4
 
5
- [![npm version](https://badgen.net/npm/v/graphql-upload)](https://npm.im/graphql-upload) [![Build status](https://travis-ci.org/jaydenseric/graphql-upload.svg?branch=master)](https://travis-ci.org/jaydenseric/graphql-upload)
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
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
8
 
@@ -12,11 +12,10 @@ Middleware and an [`Upload` scalar](#class-graphqlupload) to add support for [Gr
12
12
 
13
13
  The following environments are known to be compatible:
14
14
 
15
- - Node.js v8.5+
16
- - CJS
17
- - Native ESM with [`--experimental-modules`](https://nodejs.org/api/esm.html#esm_enabling)
15
+ - [Node.js](https://nodejs.org) `^10.13.0 || ^12.0.0 || >= 13.7.0`
18
16
  - [Koa](https://koajs.com)
19
17
  - [`graphql-api-koa`](https://npm.im/graphql-api-koa)
18
+ - [`koa-graphql`](https://npm.im/koa-graphql)
20
19
  - [`apollo-server-koa`](https://npm.im/apollo-server-koa) (inbuilt)
21
20
  - [Express](https://expressjs.com)
22
21
  - [`express-graphql`](https://npm.im/express-graphql)
@@ -50,7 +49,7 @@ See the [example API and client](https://github.com/jaydenseric/apollo-upload-ex
50
49
  - The device requires sufficient disk space to buffer the expected number of concurrent upload requests.
51
50
  - Promisify and await file upload streams in resolvers or the server will send a response to the client before uploads are complete, causing a disconnect.
52
51
  - Handle file upload promise rejection and stream errors; uploads sometimes fail due to network connectivity issues or impatient users disconnecting.
53
- - Process multiple uploads asynchronously with [`Promise.all`](https://developer.mozilla.org/docs/web/javascript/reference/global_objects/promise/all) or a more flexible solution where an error in one does not reject them all.
52
+ - Process multiple uploads asynchronously with [`Promise.all`](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/promise/all) or a more flexible solution such as [`Promise.allSettled`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) where an error in one does not reject them all.
54
53
  - Only use [`createReadStream()`](#type-fileupload) _before_ the resolver returns; late calls (e.g. in an unawaited async function or callback) throw an error. Existing streams can still be used after a response is sent, although there are few valid reasons for not awaiting their completion.
55
54
  - Use [`stream.destroy()`](https://nodejs.org/api/stream.html#stream_readable_destroy_error) when an incomplete stream is no longer needed, or temporary files may not get cleaned up.
56
55
 
@@ -67,17 +66,19 @@ The [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-mult
67
66
  ### Table of contents
68
67
 
69
68
  - [class GraphQLUpload](#class-graphqlupload)
70
- - [Examples](#examples)
69
+ - [class Upload](#class-upload)
70
+ - [Upload instance method reject](#upload-instance-method-reject)
71
+ - [Upload instance method resolve](#upload-instance-method-resolve)
72
+ - [Upload instance property file](#upload-instance-property-file)
73
+ - [Upload instance property promise](#upload-instance-property-promise)
71
74
  - [function graphqlUploadExpress](#function-graphqluploadexpress)
72
- - [Examples](#examples-1)
73
75
  - [function graphqlUploadKoa](#function-graphqluploadkoa)
74
- - [Examples](#examples-2)
75
76
  - [function processRequest](#function-processrequest)
76
- - [Examples](#examples-3)
77
77
  - [type FileUpload](#type-fileupload)
78
+ - [type FileUploadCreateReadStream](#type-fileuploadcreatereadstream)
78
79
  - [type GraphQLOperation](#type-graphqloperation)
79
- - [See](#see)
80
- - [type UploadOptions](#type-uploadoptions)
80
+ - [type ProcessRequestFunction](#type-processrequestfunction)
81
+ - [type ProcessRequestOptions](#type-processrequestoptions)
81
82
 
82
83
  ### class GraphQLUpload
83
84
 
@@ -85,30 +86,53 @@ A GraphQL `Upload` scalar that can be used in a [`GraphQLSchema`](https://graphq
85
86
 
86
87
  #### Examples
87
88
 
88
- _Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema)._
89
+ _Ways to `import`._
89
90
 
90
91
  > ```js
91
- > import { makeExecutableSchema } from 'graphql-tools'
92
- > import { GraphQLUpload } from 'graphql-upload'
92
+ > import { GraphQLUpload } from 'graphql-upload';
93
+ > ```
93
94
  >
94
- > const typeDefs = `
95
- > scalar Upload
96
- > `
95
+ > ```js
96
+ > import GraphQLUpload from 'graphql-upload/public/GraphQLUpload.js';
97
+ > ```
98
+
99
+ _Ways to `require`._
100
+
101
+ > ```js
102
+ > const { GraphQLUpload } = require('graphql-upload');
103
+ > ```
97
104
  >
98
- > const resolvers = {
99
- > Upload: GraphQLUpload
100
- > }
105
+ > ```js
106
+ > const GraphQLUpload = require('graphql-upload/public/GraphQLUpload');
107
+ > ```
108
+
109
+ _Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema)._
110
+
111
+ > ```js
112
+ > const { makeExecutableSchema } = require('graphql-tools');
113
+ > const { GraphQLUpload } = require('graphql-upload');
101
114
  >
102
- > export const schema = makeExecutableSchema({ typeDefs, resolvers })
115
+ > const schema = makeExecutableSchema({
116
+ > typeDefs: /* GraphQL */ `
117
+ > scalar Upload
118
+ > `,
119
+ > resolvers: {
120
+ > Upload: GraphQLUpload,
121
+ > },
122
+ > });
103
123
  > ```
104
124
 
105
125
  _A manually constructed schema with an image upload mutation._
106
126
 
107
127
  > ```js
108
- > import { GraphQLSchema, GraphQLObjectType, GraphQLBoolean } from 'graphql'
109
- > import { GraphQLUpload } from 'graphql-upload'
128
+ > const {
129
+ > GraphQLSchema,
130
+ > GraphQLObjectType,
131
+ > GraphQLBoolean,
132
+ > } = require('graphql');
133
+ > const { GraphQLUpload } = require('graphql-upload');
110
134
  >
111
- > export const schema = new GraphQLSchema({
135
+ > const schema = new GraphQLSchema({
112
136
  > mutation: new GraphQLObjectType({
113
137
  > name: 'Mutation',
114
138
  > fields: {
@@ -118,42 +142,119 @@ _A manually constructed schema with an image upload mutation._
118
142
  > args: {
119
143
  > image: {
120
144
  > description: 'Image file.',
121
- > type: GraphQLUpload
122
- > }
145
+ > type: GraphQLUpload,
146
+ > },
123
147
  > },
124
148
  > async resolve(parent, { image }) {
125
- > const { filename, mimetype, createReadStream } = await image
126
- > const stream = createReadStream()
149
+ > const { filename, mimetype, createReadStream } = await image;
150
+ > const stream = createReadStream();
127
151
  > // Promisify the stream and store the file, then…
128
- > return true
129
- > }
130
- > }
131
- > }
132
- > })
133
- > })
152
+ > return true;
153
+ > },
154
+ > },
155
+ > },
156
+ > }),
157
+ > });
134
158
  > ```
135
159
 
136
160
  ---
137
161
 
162
+ ### class Upload
163
+
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.
165
+
166
+ #### Examples
167
+
168
+ _Ways to `import`._
169
+
170
+ > ```js
171
+ > import { Upload } from 'graphql-upload';
172
+ > ```
173
+ >
174
+ > ```js
175
+ > import Upload from 'graphql-upload/public/Upload.js';
176
+ > ```
177
+
178
+ _Ways to `require`._
179
+
180
+ > ```js
181
+ > const { Upload } = require('graphql-upload');
182
+ > ```
183
+ >
184
+ > ```js
185
+ > const Upload = require('graphql-upload/public/Upload');
186
+ > ```
187
+
188
+ #### Upload instance method reject
189
+
190
+ Rejects the upload promise with an error. This should only be utilized by [`processRequest`](#function-processrequest).
191
+
192
+ | Parameter | Type | Description |
193
+ | :-------- | :----- | :-------------- |
194
+ | `error` | object | Error instance. |
195
+
196
+ #### Upload instance method resolve
197
+
198
+ Resolves the upload promise with the file upload details. This should only be utilized by [`processRequest`](#function-processrequest).
199
+
200
+ | Parameter | Type | Description |
201
+ | :-------- | :----------------------------- | :------------------- |
202
+ | `file` | [FileUpload](#type-fileupload) | File upload details. |
203
+
204
+ #### Upload instance property file
205
+
206
+ The file upload details, available when the [upload promise](#upload-instance-property-promise) resolves. This should only be utilized by [`processRequest`](#function-processrequest).
207
+
208
+ **Type:** `undefined` | [FileUpload](#type-fileupload)
209
+
210
+ #### Upload instance property promise
211
+
212
+ Promise that resolves file upload details. This should only be utilized by [`GraphQLUpload`](#class-graphqlupload).
213
+
214
+ **Type:** Promise<[FileUpload](#type-fileupload)>
215
+
216
+ ---
217
+
138
218
  ### function graphqlUploadExpress
139
219
 
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.
220
+ Creates [Express](https://expressjs.com) middleware that processes [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec) 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.
141
221
 
142
- | Parameter | Type | Description |
143
- | :-------- | :----------------------------------- | :---------------------- |
144
- | `options` | [UploadOptions](#type-uploadoptions) | GraphQL upload options. |
222
+ | Parameter | Type | Description |
223
+ | :-- | :-- | :-- |
224
+ | `options` | [ProcessRequestOptions](#type-processrequestoptions) | Middleware options. Any [`ProcessRequestOptions`](#type-processrequestoptions) can be used. |
225
+ | `options.processRequest` | [ProcessRequestFunction](#type-processrequestfunction)? = [processRequest](#function-processrequest) | Used to process [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). |
145
226
 
146
- **Returns:** function — Express middleware.
227
+ **Returns:** Function — Express middleware.
147
228
 
148
229
  #### Examples
149
230
 
231
+ _Ways to `import`._
232
+
233
+ > ```js
234
+ > import { graphqlUploadExpress } from 'graphql-upload';
235
+ > ```
236
+ >
237
+ > ```js
238
+ > import graphqlUploadExpress from 'graphql-upload/public/graphqlUploadExpress.js';
239
+ > ```
240
+
241
+ _Ways to `require`._
242
+
243
+ > ```js
244
+ > const { graphqlUploadExpress } = require('graphql-upload');
245
+ > ```
246
+ >
247
+ > ```js
248
+ > const graphqlUploadExpress = require('graphql-upload/public/graphqlUploadExpress');
249
+ > ```
250
+
150
251
  _Basic [`express-graphql`](https://npm.im/express-graphql) setup._
151
252
 
152
253
  > ```js
153
- > import express from 'express'
154
- > import graphqlHTTP from 'express-graphql'
155
- > import { graphqlUploadExpress } from 'graphql-upload'
156
- > import schema from './schema'
254
+ > const express = require('express');
255
+ > const graphqlHTTP = require('express-graphql');
256
+ > const { graphqlUploadExpress } = require('graphql-upload');
257
+ > const schema = require('./schema');
157
258
  >
158
259
  > express()
159
260
  > .use(
@@ -161,76 +262,126 @@ _Basic [`express-graphql`](https://npm.im/express-graphql) setup._
161
262
  > graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
162
263
  > graphqlHTTP({ schema })
163
264
  > )
164
- > .listen(3000)
265
+ > .listen(3000);
165
266
  > ```
166
267
 
167
268
  ---
168
269
 
169
270
  ### function graphqlUploadKoa
170
271
 
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.
272
+ Creates [Koa](https://koajs.com) middleware that processes [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec) 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.
172
273
 
173
- | Parameter | Type | Description |
174
- | :-------- | :----------------------------------- | :---------------------- |
175
- | `options` | [UploadOptions](#type-uploadoptions) | GraphQL upload options. |
274
+ | Parameter | Type | Description |
275
+ | :-- | :-- | :-- |
276
+ | `options` | [ProcessRequestOptions](#type-processrequestoptions) | Middleware options. Any [`ProcessRequestOptions`](#type-processrequestoptions) can be used. |
277
+ | `options.processRequest` | [ProcessRequestFunction](#type-processrequestfunction)? = [processRequest](#function-processrequest) | Used to process [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). |
176
278
 
177
- **Returns:** function — Koa middleware.
279
+ **Returns:** Function — Koa middleware.
178
280
 
179
281
  #### Examples
180
282
 
283
+ _Ways to `import`._
284
+
285
+ > ```js
286
+ > import { graphqlUploadKoa } from 'graphql-upload';
287
+ > ```
288
+ >
289
+ > ```js
290
+ > import graphqlUploadKoa from 'graphql-upload/public/graphqlUploadKoa.js';
291
+ > ```
292
+
293
+ _Ways to `require`._
294
+
295
+ > ```js
296
+ > const { graphqlUploadKoa } = require('graphql-upload');
297
+ > ```
298
+ >
299
+ > ```js
300
+ > const graphqlUploadKoa = require('graphql-upload/public/graphqlUploadKoa');
301
+ > ```
302
+
181
303
  _Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
182
304
 
183
305
  > ```js
184
- > import Koa from 'koa'
185
- > import bodyParser from 'koa-bodyparser'
186
- > import { errorHandler, execute } from 'graphql-api-koa'
187
- > import { graphqlUploadKoa } from 'graphql-upload'
188
- > import schema from './schema'
306
+ > const Koa = require('koa');
307
+ > const bodyParser = require('koa-bodyparser');
308
+ > const { errorHandler, execute } = require('graphql-api-koa');
309
+ > const { graphqlUploadKoa } = require('graphql-upload');
310
+ > const schema = require('./schema');
189
311
  >
190
312
  > new Koa()
191
313
  > .use(errorHandler())
192
314
  > .use(bodyParser())
193
315
  > .use(graphqlUploadKoa({ maxFileSize: 10000000, maxFiles: 10 }))
194
316
  > .use(execute({ schema }))
195
- > .listen(3000)
317
+ > .listen(3000);
196
318
  > ```
197
319
 
198
320
  ---
199
321
 
200
322
  ### function processRequest
201
323
 
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.
203
-
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. |
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.
209
325
 
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).
326
+ **Type:** [ProcessRequestFunction](#type-processrequestfunction)
211
327
 
212
328
  #### Examples
213
329
 
214
- _How to import._
330
+ _Ways to `import`._
215
331
 
216
332
  > ```js
217
- > import { processRequest } from 'graphql-upload'
333
+ > import { processRequest } from 'graphql-upload';
334
+ > ```
335
+ >
336
+ > ```js
337
+ > import processRequest from 'graphql-upload/public/processRequest.js';
338
+ > ```
339
+
340
+ _Ways to `require`._
341
+
342
+ > ```js
343
+ > const { processRequest } = require('graphql-upload');
344
+ > ```
345
+ >
346
+ > ```js
347
+ > const processRequest = require('graphql-upload/public/processRequest');
218
348
  > ```
219
349
 
220
350
  ---
221
351
 
222
352
  ### type FileUpload
223
353
 
224
- File upload details, resolved from an [`Upload` scalar](#class-graphqlupload) promise.
354
+ File upload details that are only available after the file’s field in the [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec) has begun streaming in.
225
355
 
226
- **Type:** Object
356
+ **Type:** object
227
357
 
228
358
  | Property | Type | Description |
229
359
  | :-- | :-- | :-- |
230
360
  | `filename` | string | File name. |
231
361
  | `mimetype` | string | File MIME type. Provided by the client and can’t be trusted. |
232
362
  | `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. |
363
+ | `createReadStream` | [FileUploadCreateReadStream](#type-fileuploadcreatereadstream) | Creates a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of the file’s contents, for processing and storage. |
364
+
365
+ ---
366
+
367
+ ### type FileUploadCreateReadStream
368
+
369
+ Creates a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of an [uploading file’s](#type-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.
370
+
371
+ **Type:** Function
372
+
373
+ | Parameter | Type | Description |
374
+ | :-- | :-- | :-- |
375
+ | `options` | object? | [`fs-capacitor`](https://npm.im/fs-capacitor) [`ReadStreamOptions`](https://github.com/mike-marcacci/fs-capacitor#readstreamoptions). |
376
+ | `options.encoding` | string? = `null` | Specify an encoding for the [`data`](https://nodejs.org/api/stream.html#stream_event_data) chunks to be strings (without splitting multi-byte characters across chunks) instead of Node.js [`Buffer`](https://nodejs.org/api/buffer.html#buffer_buffer) instances. Supported values depend on the [`Buffer` implementation](https://github.com/nodejs/node/blob/v13.7.0/lib/buffer.js#L587-L663) and include `utf8`, `ucs2`, `utf16le`, `latin1`, `ascii`, `base64`, or `hex`. |
377
+ | `options.highWaterMark` | number? = `16384` | Maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. |
378
+
379
+ **Returns:** Readable — [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of the file’s contents.
380
+
381
+ #### See
382
+
383
+ - [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).
234
385
 
235
386
  ---
236
387
 
@@ -238,13 +389,13 @@ File upload details, resolved from an [`Upload` scalar](#class-graphqlupload) pr
238
389
 
239
390
  A GraphQL operation object in a shape that can be consumed and executed by most GraphQL servers.
240
391
 
241
- **Type:** Object
392
+ **Type:** object
242
393
 
243
394
  | Property | Type | Description |
244
395
  | :-- | :-- | :-- |
245
396
  | `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. |
397
+ | `operationName` | string \| `null`? | GraphQL document operation name to execute. |
398
+ | `variables` | object \| `null`? | GraphQL document operation variables and values map. |
248
399
 
249
400
  #### See
250
401
 
@@ -253,14 +404,34 @@ A GraphQL operation object in a shape that can be consumed and executed by most
253
404
 
254
405
  ---
255
406
 
256
- ### type UploadOptions
407
+ ### type ProcessRequestFunction
408
+
409
+ Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
410
+
411
+ **Type:** Function
412
+
413
+ | Parameter | Type | Description |
414
+ | :-- | :-- | :-- |
415
+ | `request` | IncomingMessage | [Node.js HTTP server request instance](https://nodejs.org/api/http.html#http_class_http_incomingmessage). |
416
+ | `response` | ServerResponse | [Node.js HTTP server response instance](https://nodejs.org/api/http.html#http_class_http_serverresponse). |
417
+ | `options` | [ProcessRequestOptions](#type-processrequestoptions)? | Options for processing the request. |
418
+
419
+ **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
+
421
+ #### See
422
+
423
+ - [`processRequest`](#function-processrequest).
424
+
425
+ ---
426
+
427
+ ### type ProcessRequestOptions
257
428
 
258
- GraphQL upload server options, mostly relating to security, performance and limits.
429
+ Options for processing a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec); mostly relating to security, performance and limits.
259
430
 
260
- **Type:** Object
431
+ **Type:** object
261
432
 
262
433
  | Property | Type | Description |
263
434
  | :-- | :-- | :-- |
264
435
  | `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. |
436
+ | `maxFileSize` | number? = Infinity | Maximum allowed file size in bytes. |
437
+ | `maxFiles` | number? = Infinity | Maximum allowed number of files. |
@@ -1,21 +0,0 @@
1
- 'use strict'
2
-
3
- exports.__esModule = true
4
- exports.GraphQLUpload = void 0
5
-
6
- var _graphql = require('graphql')
7
-
8
- const GraphQLUpload = new _graphql.GraphQLScalarType({
9
- name: 'Upload',
10
- description: 'The `Upload` scalar type represents a file upload.',
11
- parseValue: value => value,
12
-
13
- parseLiteral() {
14
- throw new Error('‘Upload’ scalar literal unsupported.')
15
- },
16
-
17
- serialize() {
18
- throw new Error('‘Upload’ scalar serialization unsupported.')
19
- }
20
- })
21
- exports.GraphQLUpload = GraphQLUpload
@@ -1,14 +0,0 @@
1
- import { GraphQLScalarType } from 'graphql'
2
- export const GraphQLUpload = new GraphQLScalarType({
3
- name: 'Upload',
4
- description: 'The `Upload` scalar type represents a file upload.',
5
- parseValue: value => value,
6
-
7
- parseLiteral() {
8
- throw new Error('‘Upload’ scalar literal unsupported.')
9
- },
10
-
11
- serialize() {
12
- throw new Error('‘Upload’ scalar serialization unsupported.')
13
- }
14
- })
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- exports.__esModule = true
4
- exports.graphqlUploadExpress = void 0
5
-
6
- var _processRequest = require('./processRequest')
7
-
8
- const graphqlUploadExpress = options => (request, response, next) => {
9
- if (!request.is('multipart/form-data')) return next()
10
- const finished = new Promise(resolve => request.on('end', resolve))
11
- const { send } = response
12
-
13
- response.send = (...args) => {
14
- finished.then(() => {
15
- response.send = send
16
- response.send(...args)
17
- })
18
- }
19
-
20
- ;(0, _processRequest.processRequest)(request, response, options)
21
- .then(body => {
22
- request.body = body
23
- next()
24
- })
25
- .catch(error => {
26
- if (error.status && error.expose) response.status(error.status)
27
- next(error)
28
- })
29
- }
30
-
31
- exports.graphqlUploadExpress = graphqlUploadExpress
@@ -1,23 +0,0 @@
1
- import { processRequest } from './processRequest'
2
- export const graphqlUploadExpress = options => (request, response, next) => {
3
- if (!request.is('multipart/form-data')) return next()
4
- const finished = new Promise(resolve => request.on('end', resolve))
5
- const { send } = response
6
-
7
- response.send = (...args) => {
8
- finished.then(() => {
9
- response.send = send
10
- response.send(...args)
11
- })
12
- }
13
-
14
- processRequest(request, response, options)
15
- .then(body => {
16
- request.body = body
17
- next()
18
- })
19
- .catch(error => {
20
- if (error.status && error.expose) response.status(error.status)
21
- next(error)
22
- })
23
- }
@@ -1,24 +0,0 @@
1
- 'use strict'
2
-
3
- exports.__esModule = true
4
- exports.graphqlUploadKoa = void 0
5
-
6
- var _processRequest = require('./processRequest')
7
-
8
- const graphqlUploadKoa = options => async (ctx, next) => {
9
- if (!ctx.request.is('multipart/form-data')) return next()
10
- const finished = new Promise(resolve => ctx.req.on('end', resolve))
11
-
12
- try {
13
- ctx.request.body = await (0, _processRequest.processRequest)(
14
- ctx.req,
15
- ctx.res,
16
- options
17
- )
18
- await next()
19
- } finally {
20
- await finished
21
- }
22
- }
23
-
24
- exports.graphqlUploadKoa = graphqlUploadKoa
@@ -1,12 +0,0 @@
1
- import { processRequest } from './processRequest'
2
- export const graphqlUploadKoa = options => async (ctx, next) => {
3
- if (!ctx.request.is('multipart/form-data')) return next()
4
- const finished = new Promise(resolve => ctx.req.on('end', resolve))
5
-
6
- try {
7
- ctx.request.body = await processRequest(ctx.req, ctx.res, options)
8
- await next()
9
- } finally {
10
- await finished
11
- }
12
- }
package/lib/index.js DELETED
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- exports.__esModule = true
4
-
5
- var _GraphQLUpload = require('./GraphQLUpload')
6
-
7
- Object.keys(_GraphQLUpload).forEach(function(key) {
8
- if (key === 'default' || key === '__esModule') return
9
- exports[key] = _GraphQLUpload[key]
10
- })
11
-
12
- var _processRequest = require('./processRequest')
13
-
14
- Object.keys(_processRequest).forEach(function(key) {
15
- if (key === 'default' || key === '__esModule') return
16
- exports[key] = _processRequest[key]
17
- })
18
-
19
- var _graphqlUploadKoa = require('./graphqlUploadKoa')
20
-
21
- Object.keys(_graphqlUploadKoa).forEach(function(key) {
22
- if (key === 'default' || key === '__esModule') return
23
- exports[key] = _graphqlUploadKoa[key]
24
- })
25
-
26
- var _graphqlUploadExpress = require('./graphqlUploadExpress')
27
-
28
- Object.keys(_graphqlUploadExpress).forEach(function(key) {
29
- if (key === 'default' || key === '__esModule') return
30
- exports[key] = _graphqlUploadExpress[key]
31
- })
package/lib/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- export * from './GraphQLUpload'
2
- export * from './processRequest'
3
- export * from './graphqlUploadKoa'
4
- export * from './graphqlUploadExpress'