Maybe the best practice for GraphQL on node.js project.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.editorconfig
.eslintrc
.gitignore
.npmignore
.travis.yml
LICENSE
Makefile
README.md
codecov.yml
index.js
package.json

README.md

GraphQLBoot

NPM version Build Status Dependencies Status npm codecov License

Maybe the best practice for GraphQL on node.js project.

Features:

  • Using decorator @GraphqlSchema to define GraphQL schema so that you could write schema & resolver together
  • graphql tag for IDE syntax highlight
  • Scanning all *.graphqls file as GraphQL schema, for better experience of WebStorm Plugin JS GraphQL
  • Built-in common scalars such as JSON/URL/UnixTimestamp/Range, etc.
  • Connection maker to help you create relay connection with database easier

Before using GraphQLBoot:

var express = require('express');
var bodyParser = require('body-parser');
var { graphqlExpress, graphiqlExpress } = require('apollo-server-express');
var { makeExecutableSchema } = require('graphql-tools');

var typeDefs = [`
type Query {
  hello: String
}

schema {
  query: Query
}`];

var resolvers = {
  Query: {
    hello(root) {
      return 'world';
    }
  }
};

var schema = makeExecutableSchema({
  typeDefs,
  resolvers
});
var app = express();
app.use('/graphql', bodyParser.json(), graphqlExpress({schema}));
app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
app.listen(4000, () => console.log('Now browse to localhost:4000/graphiql'));

After using GraphQLBoot:

import GraphqlBoot, {GraphqlSchema, graphql} from 'graphql-boot';
import { graphiqlExpress, graphqlExpress } from 'apollo-server-express/dist/index';
import express from 'express';

const app = express();
const resolvers = {
  Query: {
    @GraphqlSchema(graphql`
        extend type Query {
            hello: String
        }
    `)    
    hello: async() => {
      return 'world';
    }
  }
}
const graphqlBoot = new GraphqlBoot();
app.use('/api', graphqlExpress({
  schema: graphqlBoot.getSchema({
    typeDefs: [],
    resolvers
  })
}));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/api' }));
app.listen(4000, () => console.log('Now browse to localhost:4000/graphiql'));

Check a full project to get more details: avnpc.js