0.1.0 • Published 7 years ago

koa-graphql-upload v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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