Registry / storage / graphql-upload-commonjs

graphql-upload-commonjs

JSON →
library16.0.2-beta.3jsnpmunverified

Middleware and Upload scalar for GraphQL multipart requests (file uploads via queries and mutations) in Node.js. Version 16.0.2-beta.3. Supports Koa, Express, and Apollo servers. Beta release with CommonJS support. Key differentiators: direct integration with graphql-upload ecosystem, supports file deduplication, streaming uploads, and custom middleware via processRequest. Peer dependencies: @types/express, @types/koa, graphql ^16.3.0. Requires Node ^14.17.0 || ^16.0.0 || >= 18.0.0.

npm install graphql-upload-commonjs
INSTALL
IMPORT
SIG · GRAPHQL-UPLOAD-COM
G
graphql-upload-commonjs
storagejavascriptv16.0.2-beta.3
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.

graphqlUploadKoa
import { graphqlUploadKoa } from 'graphql-upload-commonjs'
const graphqlUploadKoa = require('graphql-upload-commonjs').graphqlUploadKoa
ESM import is preferred but named export also works with CommonJS require.
graphqlUploadExpress
import { graphqlUploadExpress } from 'graphql-upload-commonjs'
const { graphqlUploadExpress } = require('graphql-upload-commonjs')
Both ESM and CommonJS supported but ESM import is recommended.
processRequest
import { processRequest } from 'graphql-upload-commonjs'
const processRequest = require('graphql-upload-commonjs').processRequest
Use for custom middleware; exports both as named export.
GraphQLUpload
import { GraphQLUpload } from 'graphql-upload-commonjs'
import GraphQLUpload from 'graphql-upload-commonjs'
GraphQLUpload is a named export, not default.

Express server with graphql-upload middleware handling single file upload mutation.

import express from 'express'; import { graphqlHTTP } from 'express-graphql'; import { buildSchema, GraphQLScalarType } from 'graphql'; import { graphqlUploadExpress, GraphQLUpload } from 'graphql-upload-commonjs'; const schema = buildSchema(` scalar Upload type File { filename: String mimetype: String encoding: String } type Query { uploads: [File] } type Mutation { singleUpload(file: Upload!): File! } `); const resolvers = { Upload: GraphQLUpload, Query: { uploads: () => [] }, Mutation: { singleUpload: async (parent, { file }) => { const { createReadStream, filename, mimetype, encoding } = await file; const stream = createReadStream(); // Process stream... return { filename, mimetype, encoding }; } } }; const app = express(); app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 })); app.use('/graphql', graphqlHTTP({ schema, rootValue: resolvers, graphiql: true })); app.listen(4000, () => console.log('Server running on http://localhost:4000/graphql'));
Debug
Known issues
breakingVersion 16.0.0 dropped support for Node <14.17.0, removed deprecated exports, and changed export structure
fix
Update Node to ^14.17.0 || ^16.0.0 || >=18.0.0; use named imports from 'graphql-upload-commonjs'.
affects: >=16.0.0
deprecatedThe old package 'graphql-upload' without CommonJS support is deprecated; use 'graphql-upload-commonjs' for CommonJS compatibility
fix
Switch to 'graphql-upload-commonjs'.
affects: >=16.0.0
gotchaGraphQLUpload is a named export, not default; attempting to import it as default will result in undefined
fix
Use import { GraphQLUpload } from 'graphql-upload-commonjs'.
affects: >=16.0.0
gotchaprocessRequest must be called with the correct signature; missing options can cause memory leaks
fix
Always provide an options object with maxFileSize and maxFiles to avoid unbounded resource usage.
affects: >=16.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-upload-commonjs'
Package not installed or version mismatch
fix
Run npm install graphql-upload-commonjs graphql
TypeError: Cannot destructure property 'createReadStream' of 'file' as it is undefined.
Resolver not awaited the file promise
fix
Use await file before destructuring: const { createReadStream, filename, mimetype, encoding } = await file;
GraphQLUpload is not a constructor
Imported GraphQLUpload incorrectly as default instead of named export
fix
Use import { GraphQLUpload } from 'graphql-upload-commonjs'
Expected Upload to be a GraphQL scalar type
GraphQLUpload not assigned to the Upload scalar in schema resolvers
fix
Set the resolvers.Upload property to GraphQLUpload
Upgrade
Version history
16.0.2-beta.3latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL schema building and execution
@types/expressoptionalPeer dependency for Express middleware types when using TypeScript
@types/koaoptionalPeer dependency for Koa middleware types when using TypeScript
Agent activity
27 hits · last 30 days
node
26
Resources
graphql-upload-commonjs — npm install graphql-upload-commonjs · libregistry