title: Use middleware in graphql-yoga server
body: <p>hope you guys can help me.</p>
  <p>At the frontend I'm using the apollo-client. I save my access-token in memory and my refresh-token in a http-cookie. If the access-token is exp. I fetch with the next query a new one. I'm using therefor the <a href="https://github.com/newsiberian/apollo-link-token-refresh" rel="nofollow noreferrer">apollo-link-token-refresh</a>. And I get back a new valid access-token with the query I requested. I'm using the graphql-yoga server</p>
  <p>My problem:
  Before I send back the new access-token I need the new access-token in the context for the query I made originally, else I'm using the invalid old token for the query(I send the access-token in the header for each query).</p>
  <pre><code>import { GraphQLServer } from &quot;graphql-yoga&quot;;
  
  const server = new GraphQLServer({
      typeDefs: &quot;./src/schema.graphql&quot;,
      resolvers,
      context(request) {
       return { db, pubsub, prisma, request };
      },
      fragmentReplacements
  });
  
  server.express.use(
      cors({
          origin: &quot;http://localhost:8080&quot;,
          credentials: true
      })
  );
  
  server.express.post(&quot;/refresh_token&quot;, cookieParser(), async (req, res) =&gt; {
      //logic for my access-token, before I return the access-token I need it in the context 
      //for the query I make at the same time! 
      return res.send({ ok: true, accesToken: generateToken(user) });
  })
  
  server.start({ cors: false }, () =&gt; {
      console.log(&quot;The server is up!&quot;);
  });
  </code></pre>
  <p>I guess I can solve this problem with a middleware. Thx for any help</p>