koa-graphql-upload

0.1.0 • Public • Published

koa-graphql-upload

Build Status Coverage Status File upload middleware for koa-graphql (Koa Graphql Http Server)

install

npm install koa-graphql-upload

Usage

  1. Add middleware in Koa app:
import graphqlHTTP from 'koa-graphql';
import Koa from 'koa';
import koaRouter from 'koa-router';
import convert from 'koa-convert';
import upload from 'koa-graphql-upload';

const koa = new Koa();
const router = koaRouter();

router.all('/graphql', upload(), convert(graphqlHTTP({
  schema
})));

koa
  .use(router.allowedMethods())
  .use(router.routes());
  1. Then can get files through koa.context.files
...
async resolve(parentValue, args, ctx) {
  const files = ctx.files;
  //then you can do any operation with files;
}
...

For more examples see the usage-test.js and schema.js in the /src/__tests__

See also

/koa-graphql-upload/

    Package Sidebar

    Install

    npm i koa-graphql-upload

    Weekly Downloads

    4

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • easinglab