mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
.. | ||
src | ||
.npmignore | ||
package.json | ||
README.md | ||
tsconfig.json |
title | description |
---|---|
Express / Connect | Setting up Apollo Server with Express.js or Connect |
This is the Express and Connect integration of GraphQL Server. Apollo Server is a community-maintained open-source GraphQL server that works with all Node.js HTTP server frameworks: Express, Connect, Hapi, Koa and Restify. 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!