This package has been deprecated

Author message:

WARNING: This project has been renamed to @mikojs. Install using @mikojs instead.

@cat-org/koa-graphql

1.5.8 • Public • Published

@cat-org/koa-graphql · npm npm-size

Collect the graphql files to build the graphql automatically.

Install

yarn add koa graphql @cat-org/koa-graphql

Use @cat-org/koa-graphql to server

  1. Add the middleware to server.
import Koa from 'koa';
import Graphql from '@cat-org/koa-graphql';

const app = new Koa();
const graphql = new Graphql('./path-to-graphql-foder');

app.use(graphql.middleware());
  1. Write the graphql files in ./path-to-graphql-foder.
// @flow

export default {
  typeDefs: `
  type Query {
    version: String!
  }
`,
  Query: {
    version: () => '1.0.0',
  },
};

Add the additional schema

Use with string:

const graphql = new Graphql('./path-to-graphql-foder', {
  typeDefs: `
  type AdditionalType {
    key: String!
  }
  `,
  resolvers: {
    AdditionalType: () => { ... },
  },
});

Use with Array:

const graphql = new Graphql('./path-to-graphql-foder', {
  typeDefs: [
    `
  type AdditionalType {
    key: String!
  }
`,
    `
  type AdditionalTwoType {
    key: String!
  }
`,
  ],
  resolvers: {
    AdditionalType: () => { ... },
    AdditionalTwoType: () => { ... },
  },
});

Update resolver with babel watch

const graphql = new Graphql('./path-to-graphql-folder');

chokidar
  .watch('./path-to-graphql-folder', {
    ignoreInitial: true,
  })
  .on('change', (filePath: string) => {
    graphql.update(filePath);
  });

Note: This function will only update the resolvers. This can not update the schema definition becuse graphql-tool does not support add new schema definition.

Give the options to makeExecutableSchema

Expect for typeDefs and resolvers, you can add the other options in makeExecutableSchema to this middleware.

const graphql = new Graphql('./path-to-graphql-foder', {
  options: { ... },
});

Give the options to express-graphql

Expect for schema, you can add the other options to this middleware.

...
app.use(graphql.middleware({ ... }));
...

Use to compile with relay-compiler

  1. Write a bin file or make server file to be a bin file.
#! /usr/bin/env node

import Koa from 'koa';
import Graphql from '@cat-org/koa-graphql';

const app = new Koa();
const graphql = new Graphql('./path-to-graphql-foder');

(async () => {
  if (process.env.RELAY_COMPILER) {
    await graphql.relay(['relay-compiler', 'command', 'without', 'schema']);
    process.exit();
  }

  app.use(graphql.middleware());
})();
  1. Run command with the bin file.
RELAY_COMPILER=true node ./server.js

Readme

Keywords

Package Sidebar

Install

npm i @cat-org/koa-graphql

Weekly Downloads

2

Version

1.5.8

License

MIT

Unpacked Size

22.2 kB

Total Files

7

Last publish

Collaborators

  • cat-org