No description
Find a file
Evans Hauser 37d20cfe66
Import engine reporting protobuf and fix reporting readme (#1429)
* Initial revision

* Ensure dist directory exists

* Add envrc for direnv users.

* protobufjs is a runtime dependency

* 0.0.0-beta.2

* update reports.proto with FullTracesReport

* 0.0.0-beta.3

* depend on @types/long

* 0.0.0-beta.4

* instead, do not use long

* 0.0.0-beta.5

* Add Details.variablesJson

* 0.0.0-beta.6

* comment-only update to new field

* 0.0.0-beta.7

* update a-e-reporting readme to reflect production ready state

* update changelog the engine reporting

* reporting-protobuf: prepare -> prepublish
2018-07-26 17:39:11 -07:00
.circleci Import graphql-extensions+apollo-engine-reporting/no global apollo-server-env (#1259) 2018-06-27 16:29:00 -07:00
.github [apollo-bot] Update the Templates with docs label (#877) 2018-03-14 18:21:52 +00:00
.vscode Apollo Server 2.0 - Caching + RESTDataSource (#1163) 2018-06-14 23:13:33 -07:00
__mocks__ Allow dynamic configuration of data sources (#1277) 2018-07-03 11:41:43 +02:00
docs Fixed Wrong Header at unions-interfaces (#1425) 2018-07-26 14:15:58 -07:00
packages Import engine reporting protobuf and fix reporting readme (#1429) 2018-07-26 17:39:11 -07:00
test remove unused tests 2018-07-13 13:37:12 -07:00
.gitignore Add docs/db.json to the root .gitignore so prettier will ignore it. 2018-03-13 15:41:36 +02:00
.prettierrc Setup prettier (#724) 2018-01-08 15:08:01 -08:00
CHANGELOG.md Import engine reporting protobuf and fix reporting readme (#1429) 2018-07-26 17:39:11 -07:00
CONTRIBUTING.md Tick off Prettier checkmarks, which were present on CI but not locally. (#880) 2018-03-16 10:25:07 +02:00
DESIGN.md Tick off Prettier checkmarks, which were present on CI but not locally. (#880) 2018-03-16 10:25:07 +02:00
lerna.json Publish 2018-07-17 10:55:45 -07:00
LICENSE cherry-pick changes from master 2016-07-05 15:01:49 -07:00
package.json chore(deps): update dependency @types/node to v10.5.3 2018-07-25 07:26:16 +00:00
README.md Fix Circle CI badge in README 2018-06-26 16:47:33 +02:00
renovate.json bring version-2 up to date 2018-07-13 13:14:19 -07:00
ROADMAP.md Setup prettier (#724) 2018-01-08 15:08:01 -08:00
tsconfig.json Import graphql-extensions+apollo-engine-reporting/no global apollo-server-env (#1259) 2018-06-27 16:29:00 -07:00

GraphQL Server for Express, Connect, Hapi, Cloudflare workers, and more

npm version Build Status Get on Slack

Apollo Server is a community-maintained open-source GraphQL server. It works with pretty much all Node.js HTTP server frameworks, and we're happy to take PRs for more! Apollo Server works with any GraphQL schema built with GraphQL.js, so you can build your schema with that directly or with a convenience library such as graphql-tools.

Documentation

Read the docs!

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-<integration>, write a GraphQL schema, and then use one of the following snippets to get started. For more info, read the Apollo Server docs.

Installation

Run npm install --save apollo-server-<integration> and you're good to go!

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

// The GraphQL schema
const typeDefs = gql`
  type Query {
    "A simple type for getting started!"
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

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

Integrations

Often times, Apollo Server needs to be run with a particular integration. To start, run npm install --save apollo-server-<integration> where <integration> is one of the following:

  • express
  • hapi
  • lambda
  • cloudflare

If a framework is not on this list and it should be supported, please open a PR.

Express

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

// 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();
server.applyMiddleware({ app });

app.listen({ port: 4000 }, () =>
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`),
);

Connect

const connect = require('connect');
const { ApolloServer, gql } = require('apollo-server-express');
const query = require('qs-middleware');

// 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();
const path = '/graphql';

server.use(query());
server.applyMiddleware({ app, path });

app.listen({ port: 4000 }, () =>
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`),
);

Note; qs-middleware is only required if running outside of Meteor

Hapi

The code below requires Hapi 17 or higher.

const { ApolloServer, gql } = require('apollo-server-hapi');
const Hapi = require('hapi');

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

  const app = new Hapi.server({
    port: 4000,
  });

  await server.applyMiddleware({
    app,
  });

  await server.installSubscriptionHandlers(app.listener);

  await app.start();
}

StartServer().catch(error => console.log(error));

Context

The context is created for each request. The following code snippet shows the creation of a context. The arguments are the request, the request, and h, the response toolkit.

new ApolloServer({
  typeDefs,
  resolvers,
  context: async ({ request, h }) => {
    return { ... };
  },
})

AWS Lambda

Apollo Server can be run on Lambda and deployed with AWS Serverless Application Model (SAM). It requires an API Gateway with Lambda Proxy Integration.

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

// 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 });

exports.graphqlHandler = server.createHandler();

Apollo Server Development

If you want to develop Apollo Server locally you must follow the following instructions:

  • Fork this repository

  • Install the Apollo Server project in your computer

git clone https://github.com/[your-user]/apollo-server
cd apollo-server
npm install
cd packages/apollo-server-<integration>/
npm link
  • Install your local Apollo Server in other App
cd ~/myApp
npm link apollo-server-<integration>