Registry / storage / graphql-upload-minimal

graphql-upload-minimal

JSON →
library1.6.4jsnpmunverified

A minimalistic middleware and Upload scalar for handling GraphQL multipart file uploads (queries/mutations) in Node.js servers (Express, Koa, etc.). v1.6.4 (latest) supports Node ≥12 and GraphQL 0.13.1–16. Ships TypeScript types. Forked from graphql-upload with a single production dependency (busboy), no disk I/O, no temporary files, and simpler developer-friendly error messages. Does not follow strict multipart spec (no duplicate file references). Drop-in replacement for graphql-upload with minor API differences (e.g., createReadStream() must be called once with no arguments).

npm install graphql-upload-minimal
INSTALL
IMPORT
SIG · GRAPHQL-UPLOAD-MIN
G
graphql-upload-minimal
storagejavascriptv1.6.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

graphqlUploadExpress
import { graphqlUploadExpress } from 'graphql-upload-minimal'
const graphqlUploadExpress = require('graphql-upload-minimal').graphqlUploadExpress
ESM named export; correct for CJS with destructuring.
graphqlUploadKoa
import { graphqlUploadKoa } from 'graphql-upload-minimal'
import graphqlUploadKoa from 'graphql-upload-minimal'
Named export, not default. CommonJS: const { graphqlUploadKoa } = require('graphql-upload-minimal').
processRequest
import { processRequest } from 'graphql-upload-minimal'
const processRequest = require('graphql-upload-minimal/processRequest')
Exported from the package root, not a subpath.
Upload
import { Upload } from 'graphql-upload-minimal'
const Upload = require('graphql-upload-minimal').Upload
The Upload scalar class; can also be used directly in schema.

Sets up Express + Apollo Server with graphql-upload-minimal middleware, defines a Upload scalar and a singleUpload mutation.

import { graphqlUploadExpress } from 'graphql-upload-minimal'; import express from 'express'; import { ApolloServer } from '@apollo/server'; import { expressMiddleware } from '@apollo/server/express4'; const app = express(); // Apply middleware before GraphQL app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 })); const typeDefs = `#graphql scalar Upload type File { filename: String! mimetype: String! encoding: String! } type Mutation { singleUpload(file: Upload!): File! } `; const resolvers = { Upload, // required Mutation: { singleUpload: async (parent, { file }) => { const { createReadStream, filename, mimetype, encoding } = await file; const stream = createReadStream(); // Stream to S3, etc. return { filename, mimetype, encoding }; }, }, }; const server = new ApolloServer({ typeDefs, resolvers }); await server.start(); app.use('/graphql', expressMiddleware(server)); app.listen(4000, () => console.log('Server running on port 4000'));
Debug
Known issues
gotchacreateReadStream() can only be called once per file upload. Calling it more than once will throw.
fix
Ensure createReadStream() is called exactly once; store the stream if needed elsewhere.
affects: >=1.0.0
gotchacreateReadStream() does not accept any arguments. Passing arguments will throw.
fix
Call createReadStream() with no arguments.
affects: >=1.0.0
gotchaThe same file cannot be referenced twice in a single GraphQL operation; this deviates from the strict multipart spec.
fix
Do not reuse the same file variable in multiple places in one query/mutation.
affects: >=1.0.0
deprecatedOriginal graphql-upload package is no longer maintained; this fork is the recommended drop-in replacement.
fix
Replace graphql-upload with graphql-upload-minimal in package.json and update imports.
affects: >=1.0.0
gotchaMiddleware must be applied before the GraphQL endpoint middleware (e.g., before Apollo Server or express-graphql).
fix
Place app.use(graphqlUploadExpress()) before app.use('/graphql', ...).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: createReadStream is not a function
Forgetting to await the file promise before accessing createReadStream.
fix
Use const { createReadStream } = await file; instead of const { createReadStream } = file;
Must provide Upload scalar in schema
Missing the Upload scalar definition in typeDefs and/or resolver map.
fix
Add scalar Upload to typeDefs and include Upload in your resolvers object (e.g., resolvers: { Upload, Query: ..., Mutation: ... })
Cannot use GraphQLUpload from 'graphql-upload-minimal' because it is not a constructor
Attempting to use graphqlUploadExpress or graphqlUploadKoa as a constructor instead of a function.
fix
Call it as a function: app.use(graphqlUploadExpress()) not new graphqlUploadExpress().
Upgrade
Version history
1.6.4latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency; required for GraphQL schema/scalar integration
busboyrequiredonly production dependency; parses multipart form data
Agent activity
27 hits · last 30 days
node
26
OpenAI (training)
1
Resources
graphql-upload-minimal — npm install graphql-upload-minimal · libregistry