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:
Install
graphql-tools
separately in your project.Update your
ApolloServer
constructor to provide theschema
option instead oftypeDefs
,resolvers
, andschemaDirectives
. You instead pass these options to themakeExecutableSchema
function, which you provide as the value ofschema
:JavaScriptindex.js1const { 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});
Add the following definitions to your schema
typeDefs
:GraphQLschema.graphql1enum 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 theApolloServer
constructor.
For more information on the latest version of graphql-tools
, see the official documentation.