apollo-server/packages/apollo-server-express
Martijn Walraven 685d3399db Apollo Server 2.0 - Caching + RESTDataSource (#1163)
* Enable declarationMap in tsconfig.json

See http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html

* Add apollo-server-caching package and improve typings

* Remove superfluous test steps

* Add .npmignore to apollo-server-caching

* Add apollo-server-env and apollo-datasource-rest packages

* Fix broken imports

* Use prepublish instead of prepare

* cache is now passed to data sources from ApolloServer constructor

* fix Object.values to use the object passed in rather than this

* add initial datasource test

* docs: initial data source documentation

* docs: initial data source documentation

* compiles and documentation now highlights code in data-sources.md

* Some changes to the data source docs
2018-06-14 23:13:33 -07:00
..
src Apollo Server 2.0 - Caching + RESTDataSource (#1163) 2018-06-14 23:13:33 -07:00
.npmignore include readme for npm packages 2017-10-23 15:13:31 -07:00
package.json Apollo Server 2.0 - Caching + RESTDataSource (#1163) 2018-06-14 23:13:33 -07:00
README.md Remove packages for frameworks that don't yet support 2.0 2018-06-13 13:45:10 -07:00
tsconfig.json Specify full path in tsconfig imports 2018-06-14 11:57:30 -07:00

title description
Express / Connect Setting up Apollo Server with Express.js or Connect

npm version Build Status Coverage Status Get on Slack

This is the Express and Connect integration of GraphQL Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server frameworks. Read the docs. Read the CHANGELOG.

npm install apollo-server@beta apollo-server-express@beta

Express

const express = require('express');
const { registerServer } = require('apollo-server-express');
const { ApolloServer, gql } = require('apollo-server');

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
  type Query {
    hello: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
registerServer({ server, app });

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Connect

import connect from 'connect';
const { registerServer } = require('apollo-server-express');
const { ApolloServer, gql } = require('apollo-server');

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
  type Query {
    hello: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = connect();
registerServer({ server, app });

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Principles

GraphQL Server is built with the following principles in mind:

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

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