graphql-upload-ts
Version:
TypeScript-first middleware and Upload scalar for GraphQL multipart requests (file uploads) with support for Apollo Server, Express, Koa, and more.
44 lines • 1.74 kB
TypeScript
import type { NextFunction, Request, Response } from 'express';
import { type GraphQLOperation, type IncomingReq, type UploadOptions } from './process-request';
type ProcessRequestFn = <T = GraphQLOperation | GraphQLOperation[]>(req: IncomingReq, res: Pick<Response, 'once'>, options?: UploadOptions) => Promise<T>;
export interface GraphqlUploadExpressOptions extends UploadOptions {
processRequest?: ProcessRequestFn;
/**
* Whether to override the response.send method to ensure the request stream
* is fully consumed before sending the response. This prevents potential issues
* with some GraphQL server implementations.
*
* Set to `false` when using with NestJS or when you want to handle the response
* timing yourself.
*
* @default true if processRequest is provided, false otherwise
*/
overrideSendResponse?: boolean;
}
/**
* Creates Express middleware for handling GraphQL multipart requests (file uploads).
* This middleware processes multipart/form-data requests and converts them into a format
* that GraphQL servers can understand.
*
* @example Basic setup with Apollo Server
* ```typescript
* import express from 'express';
* import { graphqlUploadExpress } from 'graphql-upload-ts';
* import { ApolloServer } from '@apollo/server';
*
* const app = express();
*
* app.use(
* '/graphql',
* graphqlUploadExpress({
* maxFileSize: 10_000_000, // 10MB
* maxFiles: 10
* })
* );
*
* // Apollo Server setup continues...
* ```
*/
export declare function graphqlUploadExpress(options?: GraphqlUploadExpressOptions): (req: Request, res: Response, next: NextFunction) => void;
export {};
//# sourceMappingURL=graphql-upload-express.d.ts.map