title: Apollo Server Express + Subscriptions error
body: <p>I am working on a Express backend project (<a href="https://www.apollographql.com/docs/apollo-server/" rel="nofollow noreferrer">Apollo Server</a> + <a href="https://expressjs.com/es/" rel="nofollow noreferrer">Express</a> + <a href="https://graphql.org/learn/" rel="nofollow noreferrer">GraphQL</a>) and its frontend part is made with React.</p>
  <p>I wanted to make a number changes in the frontend according to the database changes. For instance, when a user is created. I was reading a couple of documents till arrived on <a href="https://www.apollographql.com/docs/react/data/subscriptions/" rel="nofollow noreferrer">Apollo documentation regarding React subscriptions</a>.</p>
  <p>Then I have read <a href="https://www.apollographql.com/docs/react/migrating/boost-migration/" rel="nofollow noreferrer">Apollo Boost migration to set up client manually</a> because it didn't support subscriptions. Then I moved forward till <a href="https://www.apollographql.com/docs/graphql-subscriptions/express/" rel="nofollow noreferrer">setting up Express to support subscriptions</a> but my code didn't work.</p>
  <p>This is the error I get in console:</p>
  <blockquote>
  <p>app.use(process.env.GRAPHQL_PATH, _bodyParser[&quot;default&quot;].json(), (0,
  _apolloServerExpress.graphqlExpress)({</p>
  <p>TypeError: (0 , _apolloServerExpress.graphqlExpress) is not a function
  at Object. (C:\Web\backend\src/index.js:83:5)</p>
  </blockquote>
  <p>This is the line 83: <code>graphqlExpress({ schema })</code>, I made a comment in the right of it below.</p>
  <p>First of all I had my Express like this:</p>
  <pre class="lang-js prettyprint-override"><code>import cors from 'cors';
  import express from 'express';
  import jwt from 'jsonwebtoken';
  import mongoose from 'mongoose';
  import { ApolloServer, AuthenticationError } from 'apollo-server-express';
  import errorMessages from './mensajes/errors.json';
  require('dotenv').config();
  
  import schemas from './schemas';
  import resolvers from './resolvers';
  
  import userModel from './models/usuario';
  
  const app = express();
  
  app.use(cors());
  
  const getUser = async (req) =&gt; {
      const token = req.headers.token;
  
      if (token) {
          try {
              return await jwt.verify(token, process.env.JWT_SECRET);
          } catch (e) {
              throw new AuthenticationError(mensajesError.sesionExpirada);
          }
      }
  };
  
  const server = new ApolloServer({
      typeDefs: schemas,
      resolvers,
      context: async ({ req }) =&gt; {
          if (req) {
              const me = await getUser(req);
  
              return {
                  me,
                  models: {
                      userModel
                  },
              };
          }
      }
  });
  
  server.applyMiddleware({ app, path: process.env.GRAPHQL_PATH });
  
  const options = { 
      useNewUrlParser: true, 
      useUnifiedTopology: true, 
      useCreateIndex: true 
  };
  
  app.listen(process.env.PORT, () =&gt; {
      console.clear();
      mongoose.connect('mongodb://.../sandbox', options)
      .then(() =&gt; {
          console.log(`Database and server running on port ${process.env.PORT}`);
      })
      .catch(error =&gt; {
          console.error(`The server or the database cannot start:`);
          console.error(error);
      });
  });
  </code></pre>
  <p>Then I have changed my code according to the previous Apollo documentation to:</p>
  <pre class="lang-js prettyprint-override"><code>import { graphqlExpress } from 'apollo-server-express';
  import { createServer } from 'http';
  import { execute, subscribe } from 'graphql';
  import { PubSub } from 'graphql-subscriptions';
  import { SubscriptionServer } from 'subscriptions-transport-ws';
  require('dotenv').config();
  
  import schema from './schemas';
  import resolvers from './resolvers';
  
  import userModel from './models/usuario';
  
  const app = express();
  
  app.use(
      process.env.GRAPHQL_PATH,
      bodyParser.json(),
      graphqlExpress({ schema }) // &lt;-- Line 83
  );
  
  const pubsub = new PubSub();
  const server = createServer(app);
  
  server.listen(process.env.PORT, () =&gt; {
      new SubscriptionServer({
          execute,
          subscribe,
          schema,
      }, {
          server,
          path: '/subscriptions'
      });
  });
  </code></pre>
  <p>Of course there is a lot of information missing but I still have to understand this, I guess. Do you understand that error?</p>