npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mikojs/koa-graphql

v1.10.0

Published

Collect the graphql files to build the graphql automatically.

Downloads

11

Readme

@mikojs/koa-graphql · npm npm-size

Collect the graphql files to build the graphql automatically.

Install

yarn add koa graphql @mikojs/koa-graphql

Use @mikojs/koa-graphql to server

  1. Add the middleware to server.
import Koa from 'koa';
import Graphql from '@mikojs/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 '@mikojs/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

Use in the unit testing

import Graphql from '@mikojs/koa-graphql';

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

test('test', async () => {
  expect(await graphql.query({
    source: '{ version }',
    ...
  })).toEqual({ ... });
});

This function use graphql to query, you can see here to lerna the more information.