Skip to content

Commit 8fe00a6

Browse files
authored
Update apollo-server to Apollo Server v4 (#1322)
This moves to a new package name with a slightly different API. Also mention a few of the distinctive features.
1 parent d0f485a commit 8fe00a6

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed
Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
11
---
22
name: Apollo Server
3-
description: A set of GraphQL server packages from Apollo that work with various Node.js HTTP frameworks (Express, Connect, Hapi, Koa etc).
3+
description: A GraphQL server from Apollo that works with any Node.js HTTP framework
44
url: https://www.apollographql.com/docs/apollo-server/
55
github: apollographql/apollo-server
6-
npm: "apollo-server-express"
6+
npm: "@apollo/server"
77
---
88

9-
To run a hello world server with apollo-server-express:
9+
To run a hello world server with Apollo Server:
1010

1111
```bash
12-
npm install apollo-server-express apollo-server-core express graphql
12+
npm install @apollo/server graphql
1313
```
1414

1515
Then run `node server.js` with this code in `server.js`:
1616

1717
```js
18-
import { ApolloServer } from 'apollo-server-express';
19-
import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';
20-
import express from 'express';
21-
import http from 'http';
18+
import { ApolloServer } from '@apollo/server';
19+
import { startStandaloneServer } from '@apollo/server/standalone';
2220

23-
async function startApolloServer(typeDefs, resolvers) {
24-
const app = express();
21+
const server = new ApolloServer({
22+
typeDefs,
23+
resolvers,
24+
});
2525

26-
const httpServer = http.createServer(app);
27-
28-
const server = new ApolloServer({
29-
typeDefs,
30-
resolvers,
31-
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
32-
});
33-
34-
await server.start();
35-
36-
server.applyMiddleware({ app });
37-
38-
await new Promise(resolve => httpServer.listen({ port: 4000 }, resolve));
26+
const { url } = await startStandaloneServer(server);
3927

40-
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
41-
}
28+
console.log(`🚀 Server ready at ${url}`);
4229
```
4330

44-
Apollo Server also supports all Node.js HTTP server frameworks: Express, Connect, HAPI, Koa and NestJs.
31+
Apollo Server has a built in standalone HTTP server and middleware for Express, and has an framework integration API that supports all [Node.js HTTP server frameworks and serverless environments](https://www.apollographql.com/docs/apollo-server/integrations/integration-index) via community integrations.
32+
33+
Apollo Server has a [plugin API](https://www.apollographql.com/docs/apollo-server/integrations/plugins), integration with Apollo Studio, and performance and security features such as [caching](https://www.apollographql.com/docs/apollo-server/performance/caching/), [automatic persisted queries](https://www.apollographql.com/docs/apollo-server/performance/apq/), and [CSRF prevention](https://www.apollographql.com/docs/apollo-server/security/cors#preventing-cross-site-request-forgery-csrf).

0 commit comments

Comments
 (0)