graphql-upload 12.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/package.json +25 -25
- package/private/GRAPHQL_MULTIPART_REQUEST_SPEC_URL.js +2 -2
- package/private/ignoreStream.js +2 -2
- package/public/GraphQLUpload.js +19 -19
- package/public/Upload.js +5 -5
- package/public/graphqlUploadExpress.js +13 -13
- package/public/graphqlUploadKoa.js +13 -13
- package/public/index.js +6 -6
- package/public/index.mjs +5 -5
- package/public/processRequest.js +65 -78
- package/readme.md +40 -42
- package/changelog.md +0 -530
package/readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
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
|
-
##
|
|
9
|
+
## Installation
|
|
10
10
|
|
|
11
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
|
|
|
@@ -44,14 +44,12 @@ The [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-mult
|
|
|
44
44
|
|
|
45
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.
|
|
46
46
|
|
|
47
|
-
##
|
|
47
|
+
## Requirements
|
|
48
48
|
|
|
49
|
-
- [Node.js](https://nodejs.org): `^12.
|
|
49
|
+
- [Node.js](https://nodejs.org): `^12.22.0 || ^14.17.0 || >= 16.0.0`
|
|
50
50
|
|
|
51
51
|
## API
|
|
52
52
|
|
|
53
|
-
### Table of contents
|
|
54
|
-
|
|
55
53
|
- [class GraphQLUpload](#class-graphqlupload)
|
|
56
54
|
- [class Upload](#class-upload)
|
|
57
55
|
- [Upload instance method reject](#upload-instance-method-reject)
|
|
@@ -76,28 +74,28 @@ A GraphQL `Upload` scalar that can be used in a [`GraphQLSchema`](https://graphq
|
|
|
76
74
|
_Ways to `import`._
|
|
77
75
|
|
|
78
76
|
> ```js
|
|
79
|
-
> import { GraphQLUpload } from
|
|
77
|
+
> import { GraphQLUpload } from "graphql-upload";
|
|
80
78
|
> ```
|
|
81
79
|
>
|
|
82
80
|
> ```js
|
|
83
|
-
> import GraphQLUpload from
|
|
81
|
+
> import GraphQLUpload from "graphql-upload/public/GraphQLUpload.js";
|
|
84
82
|
> ```
|
|
85
83
|
|
|
86
84
|
_Ways to `require`._
|
|
87
85
|
|
|
88
86
|
> ```js
|
|
89
|
-
> const { GraphQLUpload } = require(
|
|
87
|
+
> const { GraphQLUpload } = require("graphql-upload");
|
|
90
88
|
> ```
|
|
91
89
|
>
|
|
92
90
|
> ```js
|
|
93
|
-
> const GraphQLUpload = require(
|
|
91
|
+
> const GraphQLUpload = require("graphql-upload/public/GraphQLUpload.js");
|
|
94
92
|
> ```
|
|
95
93
|
|
|
96
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)._
|
|
97
95
|
|
|
98
96
|
> ```js
|
|
99
|
-
> const { makeExecutableSchema } = require(
|
|
100
|
-
> const { GraphQLUpload } = require(
|
|
97
|
+
> const { makeExecutableSchema } = require("@graphql-tools/schema");
|
|
98
|
+
> const { GraphQLUpload } = require("graphql-upload");
|
|
101
99
|
>
|
|
102
100
|
> const schema = makeExecutableSchema({
|
|
103
101
|
> typeDefs: /* GraphQL */ `
|
|
@@ -116,19 +114,19 @@ _A manually constructed schema with an image upload mutation._
|
|
|
116
114
|
> GraphQLSchema,
|
|
117
115
|
> GraphQLObjectType,
|
|
118
116
|
> GraphQLBoolean,
|
|
119
|
-
> } = require(
|
|
120
|
-
> const { GraphQLUpload } = require(
|
|
117
|
+
> } = require("graphql");
|
|
118
|
+
> const { GraphQLUpload } = require("graphql-upload");
|
|
121
119
|
>
|
|
122
120
|
> const schema = new GraphQLSchema({
|
|
123
121
|
> mutation: new GraphQLObjectType({
|
|
124
|
-
> name:
|
|
122
|
+
> name: "Mutation",
|
|
125
123
|
> fields: {
|
|
126
124
|
> uploadImage: {
|
|
127
|
-
> description:
|
|
125
|
+
> description: "Uploads an image.",
|
|
128
126
|
> type: GraphQLBoolean,
|
|
129
127
|
> args: {
|
|
130
128
|
> image: {
|
|
131
|
-
> description:
|
|
129
|
+
> description: "Image file.",
|
|
132
130
|
> type: GraphQLUpload,
|
|
133
131
|
> },
|
|
134
132
|
> },
|
|
@@ -155,21 +153,21 @@ A file expected to be uploaded as it has been declared in the `map` field of a [
|
|
|
155
153
|
_Ways to `import`._
|
|
156
154
|
|
|
157
155
|
> ```js
|
|
158
|
-
> import { Upload } from
|
|
156
|
+
> import { Upload } from "graphql-upload";
|
|
159
157
|
> ```
|
|
160
158
|
>
|
|
161
159
|
> ```js
|
|
162
|
-
> import Upload from
|
|
160
|
+
> import Upload from "graphql-upload/public/Upload.js";
|
|
163
161
|
> ```
|
|
164
162
|
|
|
165
163
|
_Ways to `require`._
|
|
166
164
|
|
|
167
165
|
> ```js
|
|
168
|
-
> const { Upload } = require(
|
|
166
|
+
> const { Upload } = require("graphql-upload");
|
|
169
167
|
> ```
|
|
170
168
|
>
|
|
171
169
|
> ```js
|
|
172
|
-
> const Upload = require(
|
|
170
|
+
> const Upload = require("graphql-upload/public/Upload.js");
|
|
173
171
|
> ```
|
|
174
172
|
|
|
175
173
|
#### Upload instance method reject
|
|
@@ -218,34 +216,34 @@ Creates [Express](https://expressjs.com) middleware that processes [GraphQL mult
|
|
|
218
216
|
_Ways to `import`._
|
|
219
217
|
|
|
220
218
|
> ```js
|
|
221
|
-
> import { graphqlUploadExpress } from
|
|
219
|
+
> import { graphqlUploadExpress } from "graphql-upload";
|
|
222
220
|
> ```
|
|
223
221
|
>
|
|
224
222
|
> ```js
|
|
225
|
-
> import graphqlUploadExpress from
|
|
223
|
+
> import graphqlUploadExpress from "graphql-upload/public/graphqlUploadExpress.js";
|
|
226
224
|
> ```
|
|
227
225
|
|
|
228
226
|
_Ways to `require`._
|
|
229
227
|
|
|
230
228
|
> ```js
|
|
231
|
-
> const { graphqlUploadExpress } = require(
|
|
229
|
+
> const { graphqlUploadExpress } = require("graphql-upload");
|
|
232
230
|
> ```
|
|
233
231
|
>
|
|
234
232
|
> ```js
|
|
235
|
-
> const graphqlUploadExpress = require(
|
|
233
|
+
> const graphqlUploadExpress = require("graphql-upload/public/graphqlUploadExpress.js");
|
|
236
234
|
> ```
|
|
237
235
|
|
|
238
236
|
_Basic [`express-graphql`](https://npm.im/express-graphql) setup._
|
|
239
237
|
|
|
240
238
|
> ```js
|
|
241
|
-
> const express = require(
|
|
242
|
-
> const graphqlHTTP = require(
|
|
243
|
-
> const { graphqlUploadExpress } = require(
|
|
244
|
-
> const schema = require(
|
|
239
|
+
> const express = require("express");
|
|
240
|
+
> const graphqlHTTP = require("express-graphql");
|
|
241
|
+
> const { graphqlUploadExpress } = require("graphql-upload");
|
|
242
|
+
> const schema = require("./schema");
|
|
245
243
|
>
|
|
246
244
|
> express()
|
|
247
245
|
> .use(
|
|
248
|
-
>
|
|
246
|
+
> "/graphql",
|
|
249
247
|
> graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
|
|
250
248
|
> graphqlHTTP({ schema })
|
|
251
249
|
> )
|
|
@@ -270,31 +268,31 @@ Creates [Koa](https://koajs.com) middleware that processes [GraphQL multipart re
|
|
|
270
268
|
_Ways to `import`._
|
|
271
269
|
|
|
272
270
|
> ```js
|
|
273
|
-
> import { graphqlUploadKoa } from
|
|
271
|
+
> import { graphqlUploadKoa } from "graphql-upload";
|
|
274
272
|
> ```
|
|
275
273
|
>
|
|
276
274
|
> ```js
|
|
277
|
-
> import graphqlUploadKoa from
|
|
275
|
+
> import graphqlUploadKoa from "graphql-upload/public/graphqlUploadKoa.js";
|
|
278
276
|
> ```
|
|
279
277
|
|
|
280
278
|
_Ways to `require`._
|
|
281
279
|
|
|
282
280
|
> ```js
|
|
283
|
-
> const { graphqlUploadKoa } = require(
|
|
281
|
+
> const { graphqlUploadKoa } = require("graphql-upload");
|
|
284
282
|
> ```
|
|
285
283
|
>
|
|
286
284
|
> ```js
|
|
287
|
-
> const graphqlUploadKoa = require(
|
|
285
|
+
> const graphqlUploadKoa = require("graphql-upload/public/graphqlUploadKoa.js");
|
|
288
286
|
> ```
|
|
289
287
|
|
|
290
288
|
_Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup._
|
|
291
289
|
|
|
292
290
|
> ```js
|
|
293
|
-
> const Koa = require(
|
|
294
|
-
> const bodyParser = require(
|
|
295
|
-
> const { errorHandler, execute } = require(
|
|
296
|
-
> const { graphqlUploadKoa } = require(
|
|
297
|
-
> const schema = require(
|
|
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");
|
|
298
296
|
>
|
|
299
297
|
> new Koa()
|
|
300
298
|
> .use(errorHandler())
|
|
@@ -317,21 +315,21 @@ Processes a [GraphQL multipart request](https://github.com/jaydenseric/graphql-m
|
|
|
317
315
|
_Ways to `import`._
|
|
318
316
|
|
|
319
317
|
> ```js
|
|
320
|
-
> import { processRequest } from
|
|
318
|
+
> import { processRequest } from "graphql-upload";
|
|
321
319
|
> ```
|
|
322
320
|
>
|
|
323
321
|
> ```js
|
|
324
|
-
> import processRequest from
|
|
322
|
+
> import processRequest from "graphql-upload/public/processRequest.js";
|
|
325
323
|
> ```
|
|
326
324
|
|
|
327
325
|
_Ways to `require`._
|
|
328
326
|
|
|
329
327
|
> ```js
|
|
330
|
-
> const { processRequest } = require(
|
|
328
|
+
> const { processRequest } = require("graphql-upload");
|
|
331
329
|
> ```
|
|
332
330
|
>
|
|
333
331
|
> ```js
|
|
334
|
-
> const processRequest = require(
|
|
332
|
+
> const processRequest = require("graphql-upload/public/processRequest.js");
|
|
335
333
|
> ```
|
|
336
334
|
|
|
337
335
|
---
|