No description
Find a file
Jonas Helfer 02ff573743 Update README.md
Clarify differences to express-graphql a bit more.
2016-08-01 13:31:26 -07:00
.github add PR template 2016-07-05 15:13:38 -07:00
.vscode added some vscode default settings 2016-06-10 20:48:43 -04:00
src Merge pull request #68 from apollostack/more-tests 2016-07-29 13:59:48 -07:00
.babelrc fix coverage tool for es6 with babel 2016-07-01 15:15:02 -07:00
.gitignore improve typings config 2016-06-12 22:28:36 -07:00
.npmignore add npmignore 2016-04-24 16:02:27 -07:00
.travis.yml fix post install (#66) 2016-07-29 17:03:47 -07:00
CHANGELOG.md Expose the Express response object to the options callback (#49) 2016-07-29 10:20:29 -07:00
CONTRIBUTING.md Update CONTRIBUTING.md 2016-08-01 11:48:02 -07:00
DESIGN.md fix typo in DESIGN.md 2016-07-06 17:17:30 -07:00
integrations.md updated express example usage to include graphiql 2016-06-30 08:53:51 -07:00
LICENSE cherry-pick changes from master 2016-07-05 15:01:49 -07:00
package.json chore(package): update mocha to version 3.0.0 (#73) 2016-08-01 11:33:09 -07:00
README.md Update README.md 2016-08-01 13:31:26 -07:00
ROADMAP.md Update ROADMAP.md with completed tasks 2016-08-01 11:47:24 -07:00
tsconfig.json Core refactor hapi (#36) 2016-06-18 10:19:51 -07:00
tslint.json added tslint to the projects, adjusted the npm run scripts, and added coverage support 2016-06-10 20:48:21 -04:00
typings.json Add support for connect (#58) 2016-07-28 20:19:39 -07:00

GraphQL Server for Express, Connect, HAPI and Koa

npm version Build Status Coverage Status Get on Slack

Apollo Server is a community-maintained open-source GraphQL server. It works with all Node.js HTTP server frameworks: Express, Connect, HAPI and Koa.

Principles

Apollo Server is built with the following principles in mind:

  • By the community, for the community: Apollo Server's development is driven by the needs of developers
  • Simplicity: by keeping things simple, Apollo Server is easier to use, easier to contribute to, and more secure
  • Performance: Apollo Server is well-tested and production-ready - no modifications needed

Anyone is welcome to contribute to Apollo Server, just read CONTRIBUTING.md, take a look at the roadmap and make your first PR!

Getting started

Apollo Server is super-easy to set up. Just npm-install apollo-server, write a GraphQL schema, and then use one of the following snippets to get started. For more info, read the Apollo Server docs.

Express

import express from 'express';
import { apolloExpress } from 'apollo-server';

const myGraphQLSchema = // ... define or import your schema here!
const PORT = 3000;

var app = express();

app.use('/graphql', bodyParser.json(), apolloExpress({ schema: myGraphQLSchema }));

app.listen(PORT);

Connect

import connect from 'express';
import { apolloConnect } from 'apollo-server';

const PORT = 3000;

var app = connect();

app.use('/graphql', bodyParser.json(), apolloConnect({ schema: myGraphQLSchema }));

app.listen(PORT);

HAPI

import hapi from 'hapi';

const server = new hapi.Server();

const HOST = 'localhost';
const PORT = 3000;

server.connection({
    host: HOST,
    port: PORT,
});

server.register({
    register: new ApolloHAPI(),
    options: { schema: myGraphQLSchema },
    routes: { prefix: '/graphql' },
});

Koa

import koa from 'koa';
import koaRouter from 'koa-router';
import { apolloKoa } from 'apollo-server';

const app = new koa();
const router = new koaRouter();
const PORT = 3000;

app.use(koaBody());

router.post('/graphql', apolloKoa({ schema: myGraphQLSchema }));
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(PORT);

Options

Apollo Server can be configured with an options oject with the the following fields:

  • schema: the GraphQLSchema to be used
  • context: the context value passed to resolvers during GraphQL execution
  • rootValue: the value passed to the first resolve function
  • formatError: a function to apply to every error before sending the response to clients
  • validationRules: additional GraphQL validation rules to be applied to client-specified queries
  • formatParams: a function applied for each query in a batch to format parameters before execution
  • formatResponse: a function applied to each response after execution

All options except for schema are optional.

Differences to express-graphql

Apollo Server and express-graphql are more or less the same thing (GraphQL middleware for Node.js), but there are a few key differences:

  • express-graphql works with Express and Connect, Apollo Server supports Express, Connect, HAPI and Koa.
  • express-graphql's main goal is to be a minimal reference implementation, whereas Apollo Server's goal is to be a complete production-ready GraphQL server.
  • Compared to express-graphql, Apollo Server has a simpler interface and supports exactly one way of passing queries.
  • Apollo Server separates serving GraphiQL (GraphQL UI) from responding to GraphQL requests.
  • express-graphql contains code for parsing HTTP request bodies, Apollo Server leaves that to standard packages like body-parser.

Despite express-graphql being a reference implementation, Apollo Server is actually easier to understand and more modular than express-graphql.

That said, Apollo Server is heavily inspired by express-graphql (it's the reference implementation after all). Rather than seeing the two as competing alternatives, we think that they both have separate roles in the GraphQL ecosystem: express-graphql is a reference implementation, and Apollo Server is a GraphQL server to be used in production and evolve quickly with the needs of the community. Over time, express-graphql can adopt those features of Apollo Server that have proven their worth and become established more widely.