graphql-upload 9.0.0 → 13.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
@@ -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.
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.
8
8
 
9
- ⚠️ Previously published as [`apollo-upload-server`](https://npm.im/apollo-upload-server).
9
+ ## Installation
10
10
 
11
- ## 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.
12
12
 
13
- The following environments are known to be compatible:
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:
14
14
 
15
- - [Node.js](https://nodejs.org) >= v8.10
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).
25
-
26
- ## Setup
27
-
28
- Setup is necessary if your environment doesn’t feature this package inbuilt (see **_[Support](#support)_**).
29
-
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:
31
-
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
 
@@ -49,7 +32,7 @@ See the [example API and client](https://github.com/jaydenseric/apollo-upload-ex
49
32
  - The device requires sufficient disk space to buffer the expected number of concurrent upload requests.
50
33
  - 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.
51
34
  - Handle file upload promise rejection and stream errors; uploads sometimes fail due to network connectivity issues or impatient users disconnecting.
52
- - 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.
35
+ - 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.
53
36
  - 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.
54
37
  - 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.
55
38
 
@@ -57,19 +40,27 @@ 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
 
64
- ## API
47
+ ## Requirements
48
+
49
+ - [Node.js](https://nodejs.org): `^12.22.0 || ^14.17.0 || >= 16.0.0`
65
50
 
66
- ### Table of contents
51
+ ## API
67
52
 
68
53
  - [class GraphQLUpload](#class-graphqlupload)
54
+ - [class Upload](#class-upload)
55
+ - [Upload instance method reject](#upload-instance-method-reject)
56
+ - [Upload instance method resolve](#upload-instance-method-resolve)
57
+ - [Upload instance property file](#upload-instance-property-file)
58
+ - [Upload instance property promise](#upload-instance-property-promise)
69
59
  - [function graphqlUploadExpress](#function-graphqluploadexpress)
70
60
  - [function graphqlUploadKoa](#function-graphqluploadkoa)
71
61
  - [function processRequest](#function-processrequest)
72
62
  - [type FileUpload](#type-fileupload)
63
+ - [type FileUploadCreateReadStream](#type-fileuploadcreatereadstream)
73
64
  - [type GraphQLOperation](#type-graphqloperation)
74
65
  - [type ProcessRequestFunction](#type-processrequestfunction)
75
66
  - [type ProcessRequestOptions](#type-processrequestoptions)
@@ -80,20 +71,40 @@ A GraphQL `Upload` scalar that can be used in a [`GraphQLSchema`](https://graphq
80
71
 
81
72
  #### Examples
82
73
 
83
- _Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema)._
74
+ _Ways to `import`._
75
+
76
+ > ```js
77
+ > import { GraphQLUpload } from "graphql-upload";
78
+ > ```
79
+ >
80
+ > ```js
81
+ > import GraphQLUpload from "graphql-upload/public/GraphQLUpload.js";
82
+ > ```
83
+
84
+ _Ways to `require`._
85
+
86
+ > ```js
87
+ > const { GraphQLUpload } = require("graphql-upload");
88
+ > ```
89
+ >
90
+ > ```js
91
+ > const GraphQLUpload = require("graphql-upload/public/GraphQLUpload.js");
92
+ > ```
93
+
94
+ _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)._
84
95
 
85
96
  > ```js
86
- > const { makeExecutableSchema } = require('graphql-tools')
87
- > const { GraphQLUpload } = require('graphql-upload')
97
+ > const { makeExecutableSchema } = require("@graphql-tools/schema");
98
+ > const { GraphQLUpload } = require("graphql-upload");
88
99
  >
89
100
  > const schema = makeExecutableSchema({
90
101
  > typeDefs: /* GraphQL */ `
91
102
  > scalar Upload
92
103
  > `,
93
104
  > resolvers: {
94
- > Upload: GraphQLUpload
95
- > }
96
- > })
105
+ > Upload: GraphQLUpload,
106
+ > },
107
+ > });
97
108
  > ```
98
109
 
99
110
  _A manually constructed schema with an image upload mutation._
@@ -102,37 +113,93 @@ _A manually constructed schema with an image upload mutation._
102
113
  > const {
103
114
  > GraphQLSchema,
104
115
  > GraphQLObjectType,
105
- > GraphQLBoolean
106
- > } = require('graphql')
107
- > const { GraphQLUpload } = require('graphql-upload')
116
+ > GraphQLBoolean,
117
+ > } = require("graphql");
118
+ > const { GraphQLUpload } = require("graphql-upload");
108
119
  >
109
120
  > const schema = new GraphQLSchema({
110
121
  > mutation: new GraphQLObjectType({
111
- > name: 'Mutation',
122
+ > name: "Mutation",
112
123
  > fields: {
113
124
  > uploadImage: {
114
- > description: 'Uploads an image.',
125
+ > description: "Uploads an image.",
115
126
  > type: GraphQLBoolean,
116
127
  > args: {
117
128
  > image: {
118
- > description: 'Image file.',
119
- > type: GraphQLUpload
120
- > }
129
+ > description: "Image file.",
130
+ > type: GraphQLUpload,
131
+ > },
121
132
  > },
122
133
  > async resolve(parent, { image }) {
123
- > const { filename, mimetype, createReadStream } = await image
124
- > const stream = createReadStream()
134
+ > const { filename, mimetype, createReadStream } = await image;
135
+ > const stream = createReadStream();
125
136
  > // Promisify the stream and store the file, then…
126
- > return true
127
- > }
128
- > }
129
- > }
130
- > })
131
- > })
137
+ > return true;
138
+ > },
139
+ > },
140
+ > },
141
+ > }),
142
+ > });
132
143
  > ```
133
144
 
134
145
  ---
135
146
 
147
+ ### class Upload
148
+
149
+ 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.
150
+
151
+ #### Examples
152
+
153
+ _Ways to `import`._
154
+
155
+ > ```js
156
+ > import { Upload } from "graphql-upload";
157
+ > ```
158
+ >
159
+ > ```js
160
+ > import Upload from "graphql-upload/public/Upload.js";
161
+ > ```
162
+
163
+ _Ways to `require`._
164
+
165
+ > ```js
166
+ > const { Upload } = require("graphql-upload");
167
+ > ```
168
+ >
169
+ > ```js
170
+ > const Upload = require("graphql-upload/public/Upload.js");
171
+ > ```
172
+
173
+ #### Upload instance method reject
174
+
175
+ Rejects the upload promise with an error. This should only be utilized by [`processRequest`](#function-processrequest).
176
+
177
+ | Parameter | Type | Description |
178
+ | :-------- | :----- | :-------------- |
179
+ | `error` | object | Error instance. |
180
+
181
+ #### Upload instance method resolve
182
+
183
+ Resolves the upload promise with the file upload details. This should only be utilized by [`processRequest`](#function-processrequest).
184
+
185
+ | Parameter | Type | Description |
186
+ | :-------- | :----------------------------- | :------------------- |
187
+ | `file` | [FileUpload](#type-fileupload) | File upload details. |
188
+
189
+ #### Upload instance property file
190
+
191
+ The file upload details, available when the [upload promise](#upload-instance-property-promise) resolves. This should only be utilized by [`processRequest`](#function-processrequest).
192
+
193
+ **Type:** `undefined` | [FileUpload](#type-fileupload)
194
+
195
+ #### Upload instance property promise
196
+
197
+ Promise that resolves file upload details. This should only be utilized by [`GraphQLUpload`](#class-graphqlupload).
198
+
199
+ **Type:** Promise<[FileUpload](#type-fileupload)>
200
+
201
+ ---
202
+
136
203
  ### function graphqlUploadExpress
137
204
 
138
205
  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.
@@ -146,21 +213,41 @@ Creates [Express](https://expressjs.com) middleware that processes [GraphQL mult
146
213
 
147
214
  #### Examples
148
215
 
216
+ _Ways to `import`._
217
+
218
+ > ```js
219
+ > import { graphqlUploadExpress } from "graphql-upload";
220
+ > ```
221
+ >
222
+ > ```js
223
+ > import graphqlUploadExpress from "graphql-upload/public/graphqlUploadExpress.js";
224
+ > ```
225
+
226
+ _Ways to `require`._
227
+
228
+ > ```js
229
+ > const { graphqlUploadExpress } = require("graphql-upload");
230
+ > ```
231
+ >
232
+ > ```js
233
+ > const graphqlUploadExpress = require("graphql-upload/public/graphqlUploadExpress.js");
234
+ > ```
235
+
149
236
  _Basic [`express-graphql`](https://npm.im/express-graphql) setup._
150
237
 
151
238
  > ```js
152
- > const express = require('express')
153
- > const graphqlHTTP = require('express-graphql')
154
- > const { graphqlUploadExpress } = require('graphql-upload')
155
- > const schema = require('./schema')
239
+ > const express = require("express");
240
+ > const graphqlHTTP = require("express-graphql");
241
+ > const { graphqlUploadExpress } = require("graphql-upload");
242
+ > const schema = require("./schema");
156
243
  >
157
244
  > express()
158
245
  > .use(
159
- > '/graphql',
246
+ > "/graphql",
160
247
  > graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
161
248
  > graphqlHTTP({ schema })
162
249
  > )
163
- > .listen(3000)
250
+ > .listen(3000);
164
251
  > ```
165
252
 
166
253
  ---
@@ -178,44 +265,78 @@ Creates [Koa](https://koajs.com) middleware that processes [GraphQL multipart re
178
265
 
179
266
  #### Examples
180
267
 
268
+ _Ways to `import`._
269
+
270
+ > ```js
271
+ > import { graphqlUploadKoa } from "graphql-upload";
272
+ > ```
273
+ >
274
+ > ```js
275
+ > import graphqlUploadKoa from "graphql-upload/public/graphqlUploadKoa.js";
276
+ > ```
277
+
278
+ _Ways to `require`._
279
+
280
+ > ```js
281
+ > const { graphqlUploadKoa } = require("graphql-upload");
282
+ > ```
283
+ >
284
+ > ```js
285
+ > const graphqlUploadKoa = require("graphql-upload/public/graphqlUploadKoa.js");
286
+ > ```
287
+
181
288
  _Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
182
289
 
183
290
  > ```js
184
- > const Koa = require('koa')
185
- > const bodyParser = require('koa-bodyparser')
186
- > const { errorHandler, execute } = require('graphql-api-koa')
187
- > const { graphqlUploadKoa } = require('graphql-upload')
188
- > const schema = require('./schema')
291
+ > const Koa = require("koa");
292
+ > const bodyParser = require("koa-bodyparser");
293
+ > const { errorHandler, execute } = require("graphql-api-koa");
294
+ > const { graphqlUploadKoa } = require("graphql-upload");
295
+ > const schema = require("./schema");
189
296
  >
190
297
  > new Koa()
191
298
  > .use(errorHandler())
192
299
  > .use(bodyParser())
193
300
  > .use(graphqlUploadKoa({ maxFileSize: 10000000, maxFiles: 10 }))
194
301
  > .use(execute({ schema }))
195
- > .listen(3000)
302
+ > .listen(3000);
196
303
  > ```
197
304
 
198
305
  ---
199
306
 
200
307
  ### function processRequest
201
308
 
202
- Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec). 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.
309
+ 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.
203
310
 
204
311
  **Type:** [ProcessRequestFunction](#type-processrequestfunction)
205
312
 
206
313
  #### Examples
207
314
 
208
- _How to import._
315
+ _Ways to `import`._
316
+
317
+ > ```js
318
+ > import { processRequest } from "graphql-upload";
319
+ > ```
320
+ >
321
+ > ```js
322
+ > import processRequest from "graphql-upload/public/processRequest.js";
323
+ > ```
324
+
325
+ _Ways to `require`._
209
326
 
210
327
  > ```js
211
- > const { processRequest } = require('graphql-upload')
328
+ > const { processRequest } = require("graphql-upload");
329
+ > ```
330
+ >
331
+ > ```js
332
+ > const processRequest = require("graphql-upload/public/processRequest.js");
212
333
  > ```
213
334
 
214
335
  ---
215
336
 
216
337
  ### type FileUpload
217
338
 
218
- File upload details, resolved from an [`Upload` scalar](#class-graphqlupload) promise.
339
+ 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.
219
340
 
220
341
  **Type:** object
221
342
 
@@ -224,7 +345,28 @@ File upload details, resolved from an [`Upload` scalar](#class-graphqlupload) pr
224
345
  | `filename` | string | File name. |
225
346
  | `mimetype` | string | File MIME type. Provided by the client and can’t be trusted. |
226
347
  | `encoding` | string | File stream transfer encoding. |
227
- | `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. |
348
+ | `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. |
349
+
350
+ ---
351
+
352
+ ### type FileUploadCreateReadStream
353
+
354
+ 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.
355
+
356
+ **Type:** Function
357
+
358
+ | Parameter | Type | Description |
359
+ | :-- | :-- | :-- |
360
+ | `options` | object? | [`fs-capacitor`](https://npm.im/fs-capacitor) [`ReadStreamOptions`](https://github.com/mike-marcacci/fs-capacitor#readstreamoptions). |
361
+ | `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`. |
362
+ | `options.highWaterMark` | number? = `16384` | Maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. |
363
+
364
+ **Returns:** Readable — [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of the file’s contents.
365
+
366
+ #### See
367
+
368
+ - [Node.js `Readable` stream constructor docs](https://nodejs.org/api/stream.html#stream_new_stream_readable_options).
369
+ - [Node.js stream backpressure guide](https://nodejs.org/en/docs/guides/backpressuring-in-streams).
228
370
 
229
371
  ---
230
372
 
@@ -242,8 +384,8 @@ A GraphQL operation object in a shape that can be consumed and executed by most
242
384
 
243
385
  #### See
244
386
 
245
- - [GraphQL over HTTP spec](https://github.com/APIs-guru/graphql-over-http#request-parameters).
246
- - [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests#postRequests).
387
+ - [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http).
388
+ - [Apollo Server POST requests](https://www.apollographql.com/docs/apollo-server/requests/#post-requests).
247
389
 
248
390
  ---
249
391
 
@@ -259,7 +401,11 @@ Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-m
259
401
  | `response` | ServerResponse | [Node.js HTTP server response instance](https://nodejs.org/api/http.html#http_class_http_serverresponse). |
260
402
  | `options` | [ProcessRequestOptions](#type-processrequestoptions)? | Options for processing the request. |
261
403
 
262
- **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).
404
+ **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).
405
+
406
+ #### See
407
+
408
+ - [`processRequest`](#function-processrequest).
263
409
 
264
410
  ---
265
411
 
package/GraphQLUpload.js DELETED
@@ -1,67 +0,0 @@
1
- const { GraphQLScalarType } = require('graphql')
2
-
3
- /**
4
- * A GraphQL `Upload` scalar that can be used in a [`GraphQLSchema`](https://graphql.org/graphql-js/type/#graphqlschema).
5
- * It’s value in resolvers is a promise that resolves [file upload details]{@link FileUpload}
6
- * for processing and storage.
7
- * @kind class
8
- * @name GraphQLUpload
9
- * @example <caption>Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema).</caption>
10
- * ```js
11
- * const { makeExecutableSchema } = require('graphql-tools')
12
- * const { GraphQLUpload } = require('graphql-upload')
13
- *
14
- * const schema = makeExecutableSchema({
15
- * typeDefs: /* GraphQL *\/ `
16
- * scalar Upload
17
- * `,
18
- * resolvers: {
19
- * Upload: GraphQLUpload
20
- * }
21
- * })
22
- * ```
23
- * @example <caption>A manually constructed schema with an image upload mutation.</caption>
24
- * ```js
25
- * const {
26
- * GraphQLSchema,
27
- * GraphQLObjectType,
28
- * GraphQLBoolean
29
- * } = require('graphql')
30
- * const { GraphQLUpload } = require('graphql-upload')
31
- *
32
- * const schema = new GraphQLSchema({
33
- * mutation: new GraphQLObjectType({
34
- * name: 'Mutation',
35
- * fields: {
36
- * uploadImage: {
37
- * description: 'Uploads an image.',
38
- * type: GraphQLBoolean,
39
- * args: {
40
- * image: {
41
- * description: 'Image file.',
42
- * type: GraphQLUpload
43
- * }
44
- * },
45
- * async resolve(parent, { image }) {
46
- * const { filename, mimetype, createReadStream } = await image
47
- * const stream = createReadStream()
48
- * // Promisify the stream and store the file, then…
49
- * return true
50
- * }
51
- * }
52
- * }
53
- * })
54
- * })
55
- * ```
56
- */
57
- module.exports = new GraphQLScalarType({
58
- name: 'Upload',
59
- description: 'The `Upload` scalar type represents a file upload.',
60
- parseValue: value => value,
61
- parseLiteral() {
62
- throw new Error('‘Upload’ scalar literal unsupported.')
63
- },
64
- serialize() {
65
- throw new Error('‘Upload’ scalar serialization unsupported.')
66
- }
67
- })