Skip to content

Update apollo-server to Apollo Server v4 #1322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
---
name: Apollo Server
description: A set of GraphQL server packages from Apollo that work with various Node.js HTTP frameworks (Express, Connect, Hapi, Koa etc).
description: A GraphQL server from Apollo that works with any Node.js HTTP framework
url: https://www.apollographql.com/docs/apollo-server/
github: apollographql/apollo-server
npm: "apollo-server-express"
npm: "@apollo/server"
---

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

```bash
npm install apollo-server-express apollo-server-core express graphql
npm install @apollo/server graphql
```

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

```js
import { ApolloServer } from 'apollo-server-express';
import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';
import express from 'express';
import http from 'http';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

async function startApolloServer(typeDefs, resolvers) {
const app = express();
const server = new ApolloServer({
typeDefs,
resolvers,
});

const httpServer = http.createServer(app);

const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
});

await server.start();

server.applyMiddleware({ app });

await new Promise(resolve => httpServer.listen({ port: 4000 }, resolve));
const { url } = await startStandaloneServer(server);

console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
}
console.log(`🚀 Server ready at ${url}`);
```

Apollo Server also supports all Node.js HTTP server frameworks: Express, Connect, HAPI, Koa and NestJs.
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.

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).