mercurius-upload
Advanced tools
Comparing version 6.0.1 to 7.0.0
@@ -1,14 +0,9 @@ | ||
/// <reference types="node" /> | ||
import processRequest from 'graphql-upload/processRequest.js' | ||
import type { FastifyPluginCallback } from 'fastify' | ||
import { UploadOptions } from 'graphql-upload-minimal'; | ||
import type { FastifyPluginCallback } from 'fastify'; | ||
declare module 'fastify' { | ||
interface FastifyRequest { | ||
mercuriusUploadMultipart?: true | ||
} | ||
interface FastifyRequest { | ||
mercuriusUploadMultipart?: true; | ||
} | ||
} | ||
export declare const mercuriusUpload: FastifyPluginCallback< | ||
processRequest.ProcessRequestOptions, | ||
import('http').Server, | ||
import('fastify').FastifyTypeProviderDefault | ||
> | ||
export default mercuriusUpload | ||
export declare const mercuriusUpload: FastifyPluginCallback<UploadOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault>; | ||
export default mercuriusUpload; |
@@ -1,87 +0,58 @@ | ||
'use strict' | ||
var __createBinding = | ||
(this && this.__createBinding) || | ||
(Object.create | ||
? function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k | ||
var desc = Object.getOwnPropertyDescriptor(m, k) | ||
if ( | ||
!desc || | ||
('get' in desc ? !m.__esModule : desc.writable || desc.configurable) | ||
) { | ||
desc = { | ||
enumerable: true, | ||
get: function () { | ||
return m[k] | ||
}, | ||
} | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mercuriusUpload = void 0; | ||
const util = __importStar(require("util")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const fastify_plugin_1 = __importDefault(require("fastify-plugin")); | ||
const graphql_upload_minimal_1 = require("graphql-upload-minimal"); | ||
const finishedStream = util.promisify(stream_1.default.finished); | ||
const mercuriusGQLUpload = (fastify, options, done) => { | ||
fastify.addContentTypeParser('multipart', (req, _payload, done) => { | ||
req.mercuriusUploadMultipart = true; | ||
done(null); | ||
}); | ||
fastify.addHook('preValidation', async function (request, reply) { | ||
if (!request.mercuriusUploadMultipart) { | ||
return; | ||
} | ||
Object.defineProperty(o, k2, desc) | ||
} | ||
: function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k | ||
o[k2] = m[k] | ||
}) | ||
var __setModuleDefault = | ||
(this && this.__setModuleDefault) || | ||
(Object.create | ||
? function (o, v) { | ||
Object.defineProperty(o, 'default', { enumerable: true, value: v }) | ||
} | ||
: function (o, v) { | ||
o['default'] = v | ||
}) | ||
var __importStar = | ||
(this && this.__importStar) || | ||
function (mod) { | ||
if (mod && mod.__esModule) return mod | ||
var result = {} | ||
if (mod != null) | ||
for (var k in mod) | ||
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) | ||
__createBinding(result, mod, k) | ||
__setModuleDefault(result, mod) | ||
return result | ||
} | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod } | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
exports.mercuriusUpload = void 0 | ||
const util = __importStar(require('util')) | ||
const stream_1 = __importDefault(require('stream')) | ||
const fastify_plugin_1 = __importDefault(require('fastify-plugin')) | ||
const processRequest_js_1 = __importDefault( | ||
require('graphql-upload/processRequest.js') | ||
) | ||
const finishedStream = util.promisify(stream_1.default.finished) | ||
const mercuriusGQLUpload = (fastify, options, done) => { | ||
fastify.addContentTypeParser('multipart', (req, _payload, done) => { | ||
req.mercuriusUploadMultipart = true | ||
done(null) | ||
}) | ||
fastify.addHook('preValidation', async function (request, reply) { | ||
if (!request.mercuriusUploadMultipart) { | ||
return | ||
} | ||
request.body = await (0, processRequest_js_1.default)( | ||
request.raw, | ||
reply.raw, | ||
options | ||
) | ||
}) | ||
fastify.addHook('onSend', async function (request) { | ||
if (!request.mercuriusUploadMultipart) { | ||
return | ||
} | ||
await finishedStream(request.raw) | ||
}) | ||
done() | ||
} | ||
request.body = await (0, graphql_upload_minimal_1.processRequest)(request.raw, reply.raw, options); | ||
}); | ||
fastify.addHook('onSend', async function (request) { | ||
if (!request.mercuriusUploadMultipart) { | ||
return; | ||
} | ||
await finishedStream(request.raw); | ||
}); | ||
done(); | ||
}; | ||
exports.mercuriusUpload = (0, fastify_plugin_1.default)(mercuriusGQLUpload, { | ||
fastify: '>= 4.x', | ||
name: 'mercurius-upload', | ||
}) | ||
exports.default = exports.mercuriusUpload | ||
fastify: '>= 4.x', | ||
name: 'mercurius-upload', | ||
}); | ||
exports.default = exports.mercuriusUpload; |
{ | ||
"name": "mercurius-upload", | ||
"version": "6.0.1", | ||
"version": "7.0.0", | ||
"description": "Fastify plugin to support GraphQL uploads using graphql-upload", | ||
@@ -30,8 +30,12 @@ "keywords": [ | ||
], | ||
"scripts": { | ||
"prepack": "tsc && prettier --write dist index.ts test", | ||
"test": "tap --ts --100 test/*.test.ts" | ||
}, | ||
"dependencies": { | ||
"fastify-plugin": "^4.2.0", | ||
"graphql-upload": "^15.0.1" | ||
"graphql-upload-minimal": "^1.5.5" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.11.39", | ||
"@types/node": "^20.5.0", | ||
"@types/tap": "^15.0.7", | ||
@@ -42,14 +46,11 @@ "cross-env": "^7.0.3", | ||
"graphql": "^16.5.0", | ||
"mercurius": "^10.0.0", | ||
"prettier": "^2.6.2", | ||
"mercurius": "^13.0.0", | ||
"prettier": "^3.0.0", | ||
"tap": "^16.2.0", | ||
"ts-node": "^10.8.1", | ||
"typescript": "^4.7.3" | ||
"typescript": "^5.2.2" | ||
}, | ||
"peerDependencies": { | ||
"graphql": "^16.3.0" | ||
}, | ||
"scripts": { | ||
"test": "tap --ts --100 test/*.test.ts" | ||
} | ||
} | ||
} |
# mercurius-upload | ||
[graphql-upload](https://github.com/jaydenseric/graphql-upload) implementation plugin for [Fastify](https://www.fastify.io/) & [mercurius](https://github.com/mercurius-js/mercurius). | ||
[graphql-upload-minimal](https://github.com/flash-oss/graphql-upload-minimal) implementation plugin for [Fastify](https://www.fastify.io/) & [mercurius](https://github.com/mercurius-js/mercurius). | ||
@@ -19,7 +19,9 @@ Plugin made for **Fastify v4**: | ||
Plugin options should conform to https://github.com/jaydenseric/graphql-upload#type-processrequestoptions | ||
Plugin options should conform to https://github.com/flash-oss/graphql-upload-minimal#type-processrequestoptions | ||
```js | ||
fastify.register(require('mercurius-upload'), { | ||
// options passed to processRequest from graphql-upload | ||
// options passed to processRequest from graphql-upload-minimal | ||
// maxFileSize: 1024 * 1024 * 5, | ||
// maxFiles: 1, | ||
}) | ||
@@ -36,3 +38,3 @@ ``` | ||
fastify.register(MercuriusGQLUpload, { | ||
// options passed to processRequest from graphql-upload | ||
// options passed to processRequest from graphql-upload-minimal | ||
}) | ||
@@ -45,3 +47,3 @@ ``` | ||
const GQL = require('mercurius') | ||
const { GraphQLUpload } = require('graphql-upload') | ||
const { GraphQLUpload } = require('graphql-upload-minimal') | ||
const fs = require('fs') | ||
@@ -48,0 +50,0 @@ const util = require('util') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96
7114
67
1
+ Addedgraphql-upload-minimal@1.6.1(transitive)
- Removedgraphql-upload@^15.0.1
- Removed@types/busboy@1.5.4(transitive)
- Removed@types/node@22.10.0(transitive)
- Removed@types/object-path@0.11.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removedfs-capacitor@6.2.0(transitive)
- Removedgraphql-upload@15.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedobject-path@0.11.8(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedundici-types@6.20.0(transitive)