title: How to debug an ApolloServer's context function?
body: <p>I'm trying to follow the GraphQL tutorial (<a href="https://www.apollographql.com/docs/tutorial/resolvers/" rel="nofollow noreferrer">https://www.apollographql.com/docs/tutorial/resolvers/</a>), but I'm getting an error in the playground when I try to book a trip, with a stack trace starting like this:</p>
  
  <pre><code> "TypeError: Cannot read property 'id' of null",
              "    at UserAPI.bookTrips (/Users/kurtpeek/Documents/Scratch/fullstack-tutorial/start/server/src/datasources/user.js:35:38)",
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aSoSw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aSoSw.png" alt="enter image description here"></a></p>
  
  <p>In <code>src/index.js</code>, the <code>ApolloServer</code> (<a href="https://www.apollographql.com/docs/apollo-server/api/apollo-server/" rel="nofollow noreferrer">https://www.apollographql.com/docs/apollo-server/api/apollo-server/</a>) is defined with an asynchronous <code>context()</code> function like so:</p>
  
  <pre><code>const { ApolloServer } = require('apollo-server');
  const typeDefs = require('./schema');
  const { createStore } = require('./utils');
  const resolvers = require('./resolvers');
  
  const LaunchAPI = require('./datasources/launch');
  const UserAPI = require('./datasources/user');
  const isEmail = require('isemail');
  
  const store = createStore();
  
  const server = new ApolloServer({
    context: async ({ req }) =&gt; {
      debugger;
      const auth = (req.headers &amp;&amp; req.headers.authorization) || '';
      const email = Buffer.from(auth, 'base64').toString('ascii');
      if (!isEmail.validate(email)) return { user: null };
  
      const users = await store.users.findOrCreate({ where: { email }});
      const user = users &amp;&amp; users[0] ? users[0] : null;
  
      return { user: { ...user.dataValues }};
    },
    typeDefs,
    resolvers,
    dataSources: () =&gt; ({
      launchAPI: new LaunchAPI(),
      userAPI: new UserAPI({ store })
    })
  });
  
  server.listen().then(({ url }) =&gt; {
    console.log(` Server ready at ${url}`);
  });
  </code></pre>
  
  <p>Since the error I'm seeing is the result of the context's <code>user</code> being <code>null</code>, I would like to step through the <code>context()</code> method to inspect the headers and see whether it contains a valid (encoded) email; as you can see I've set a <code>debugger</code> breakpoint at the start of that function.</p>
  
  <p>However, when I run <code>node inspect src/index.js</code>, I immediately enter the debugger for an <code>IntrospectionQuery</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/t3gSU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t3gSU.png" alt="enter image description here"></a></p>
  
  <p>If I press the 'Resume script execution' button, I just get back immediately to the same breakpoint.</p>
  
  <p>Does this have something to do with the fact that <code>context()</code> is an <code>async</code> function? How can I step through the <code>context()</code> method with the debugger?</p>