UNPKG

1.8 kBTypeScriptView Raw
1import { Context, Next } from 'koa';
2type ProcessRequestOptions = {
3 processRequest?: ((req: any, res: any, options: any) => Promise<any>) | (() => Promise<void>);
4 maxFieldSize?: number;
5 maxFileSize?: number;
6 maxFiles?: number;
7 [key: string]: any;
8};
9/**
10 * Creates [Koa](https://koajs.com) middleware that processes
11 * [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec)
12 * using [`processRequest`]{@link processRequest}, ignoring non-multipart
13 * requests. It sets the request body to be
14 * [similar to a conventional GraphQL POST request]{@link GraphQLOperation} for
15 * following GraphQL middleware to consume.
16 * @example <caption>Ways to `import`.</caption>
17 * ```js
18 * import { graphqlUploadKoa } from 'graphql-upload-ts';
19 * ```
20 *
21 * ```js
22 * import graphqlUploadKoa from 'graphql-upload-ts/dist/graphqlUploadKoa.js';
23 * ```
24 * @example <caption>Ways to `require`.</caption>
25 * ```js
26 * const { graphqlUploadKoa } = require('graphql-upload-ts');
27 * ```
28 *
29 * ```js
30 * const graphqlUploadKoa = require('graphql-upload-ts/dist/graphqlUploadKoa');
31 * ```
32 * @example <caption>Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup.</caption>
33 * ```js
34 * const Koa = require('koa');
35 * const bodyParser = require('koa-bodyparser');
36 * const { errorHandler, execute } = require('graphql-api-koa');
37 * const { graphqlUploadKoa } = require('graphql-upload-ts');
38 * const schema = require('./schema');
39 *
40 * new Koa()
41 * .use(errorHandler())
42 * .use(bodyParser())
43 * .use(graphqlUploadKoa({ maxFileSize: 10000000, maxFiles: 10 }))
44 * .use(execute({ schema }))
45 * .listen(3000);
46 * ```
47 */
48export declare function graphqlUploadKoa(params?: ProcessRequestOptions): (ctx: Context, next: Next) => Promise<any>;
49export {};
50
\No newline at end of file