Apollo Server 2.0 introduced a number of breaking changes with the intention of simplifying setup. There's a migration guide in the documentation that outlines the changes. If all you need is a GraphQL server, getting started can be as simple as this:
const { ApolloServer, gql } = require('apollo-server');const server = new ApolloServer({ typeDefs, resolvers });server.listen()
Note that the above simply uses the apollo-server
package. apollo-server-express
still exists if you want to continue to utilize Apollo as express middleware instead of running Apollo as a "standalone" server.
const { ApolloServer, gql } = require('apollo-server-express');const app = require('express')();const server = new ApolloServer({ typeDefs, resolvers });server.applyMiddleware({ app });app.listen({ port: 3000 })
The new API eliminates the need to separately import and implement additional middleware like body-parser
or cors
. Read the docs for more information about how to configure your Apollo Server instance.