Update README.md to make it much longer and more complete

This commit is contained in:
Jonas Helfer 2016-08-01 12:54:47 -07:00 committed by GitHub
parent 9f10b4f0d1
commit 1826c19f43

117
README.md
View file

@ -1,23 +1,118 @@
# Apollo-server: A GraphQL server for Node.js
# GraphQL Server for Express, Connect, HAPI and Koa
[![npm version](https://badge.fury.io/js/apollo-server.svg)](https://badge.fury.io/js/apollo-server)
[![Build Status](https://travis-ci.org/apollostack/apollo-server.svg?branch=master)](https://travis-ci.org/apollostack/apollo-server)
[![Coverage Status](https://coveralls.io/repos/github/apollostack/apollo-server/badge.svg?branch=master)](https://coveralls.io/github/apollostack/apollo-server?branch=master)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](http://www.apollostack.com/#slack)
Apollo server has integrations for Express, Connect, HAPI and Koa!
Apollo Server is a community-maintained open-source GraphQL server. It works with all Node.js HTTP server frameworks: Express, Connect, HAPI and Koa.
### Contributions
## Principles
Contributions, issues and feature requests are very welcome. If you are using this package and fixed a bug for yourself, please consider submitting a PR!
Apollo Server is built with the following principles in mind:
### Folder structure
* **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
**/src/core**:
- contains the core functionality that is independent of any particular node.js server framework
**/src/integrations/\<name\>**:
- Contains the integrations for Node.js server framework \<name\> (i.e. express, HAPI, Koa, connect)
Anyone is welcome to contribute to Apollo Server, just read [CONTRIBUTING.md](./CONTRIBUTING.md), take a look at the [roadmap](./ROADMAP.md) and make your first PR!
**/src/test**:
- Contains only the `tests.ts` file that imports other tests. All real test files go in the same folder as the code they are testing, and should be named `*.test.ts`.
## 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](http://docs.apollostack.com/apollo-server).
### Express
```js
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
```js
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
```js
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
```js
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.
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.