`graphql-upload-ts` is a TypeScript-first library designed to facilitate file uploads within GraphQL applications by providing specialized middleware and an `Upload` scalar type. The current stable version is `2.1.4`, reflecting active development with frequent beta releases. This package distinguishes itself through comprehensive TypeScript support, ensuring type-safety and robust integration across various Node.js frameworks, including Express, Koa, Apollo Server, and GraphQL Yoga. It's built for production environments, featuring efficient file streaming, high test coverage, and compatibility with the Bun runtime. A strong emphasis on security is evident through built-in file validation capabilities, and it supports both CommonJS and ESM module systems for broad project compatibility. Its detailed documentation and example implementations further enhance its usability for developers integrating file upload functionality into their GraphQL APIs.
npm install graphql-upload-tsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic GraphQL server with Express and `graphql-upload-ts` to handle file upload mutations. It configures the necessary middleware and defines a simple schema with an `uploadFile` mutation.
Ensure `app.use(graphqlUploadExpress({ ... }));` is declared and invoked prior to `app.use('/graphql', graphqlHTTP({ ... }));` or your Apollo Server integration.Upgrade your Node.js runtime to version 16.0.0 or higher to meet the minimum engine requirements.
Explicitly configure these limits in the `graphqlUploadExpress` options. For example: `graphqlUploadExpress({ maxFileSize: 20000000, maxFiles: 5 })` for 20MB files and 5 files maximum. Implement custom stream processing for extremely large files to avoid buffering entirely.Ensure `GraphQLUpload` is imported from `graphql-upload-ts` and added to your schema's type definitions, e.g., in a `types` array for `GraphQLSchema` or explicitly referenced in your schema language definition.
Verify that your client is sending a `Content-Type: multipart/form-data` header. Double-check that `graphqlUploadExpress` is correctly used and placed *before* your primary GraphQL HTTP handler middleware.
Confirm that the `file` argument in your GraphQL mutation is correctly typed as `GraphQLUpload` in the schema. Ensure the client's multipart request correctly maps the file input to the `file` argument in the GraphQL query variables.