Apollo Server 2 is officially end-of-life as of 22 October 2023.

Learn more about upgrading.

Using a different version of graphql-tools


Apollo Server includes graphql-tools version 4 by default. If you want to use a newer version, you can do so with the following steps:

  1. Install graphql-tools separately in your project.

  2. Update your ApolloServer constructor to provide the schema option instead of typeDefs, resolvers, and schemaDirectives. You instead pass these options to the makeExecutableSchema function, which you provide as the value of schema:

    JavaScript
    index.js
    1const { ApolloServer, gql } = require("apollo-server");
    2const { makeExecutableSchema } = require("@graphql-tools/schema");
    3
    4const server = new ApolloServer({
    5  schema: makeExecutableSchema({
    6    typeDefs,
    7    resolvers,
    8    schemaDirectives: {
    9      // ...directive subclasses...
    10    }
    11  }),
    12  // ...other options...
    13});
  3. Add the following definitions to your schema typeDefs:

    GraphQL
    schema.graphql
    1enum CacheControlScope {
    2  PUBLIC
    3  PRIVATE
    4}
    5
    6directive @cacheControl(
    7  maxAge: Int
    8  scope: CacheControlScope
    9) on FIELD_DEFINITION | OBJECT | INTERFACE
    10
    11scalar Upload

    Apollo Server uses these types for its caching and file upload functionality. It usually defines these types automatically on startup, but it doesn't if you provide the schema option to the ApolloServer constructor.

For more information on the latest version of graphql-tools, see the official documentation.

Feedback

Edit on GitHub

Forums