1

Before the upgrade we were having

import express from 'express';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';

const app = express();

app.use(
   '/graphql',
   bodyParser.json(),
   graphqlExpress(req => ({
   schema,
   tracing: true,
   context: { req },
 })),
);

app.use(
 '/graphiql',
 graphiqlExpress({
   endpointURL: '/graphql',
 }),
);

In our resolvers we could get the req and set req.session.token as follows,

const customResover = {
Query: {
   custom: async (root, args, context) => {
   console.log(' resolver called with args', args);
   const { req } = context;  
   ... fetch token info and set 
   req.session.token = ${token};
   ...

but with the upgrade to version 2.0.0 the code is changed to following and I am not sure how to fix the CustomResolver, to set the session token, any idea how the above could be accomplished ?

import express from 'express';
import { ApolloServer, gql } from 'apollo-server-express';
import { typeDefs, resolvers } from './schema/';

const app = express();
const apollo = new ApolloServer({
   typeDefs
   resolvers,
   engine: false
});

apollo.applyMiddleware({
   app,
});
NUS
  • 383
  • 1
  • 6
  • 17

1 Answers1

1

https://www.apollographql.com/docs/apollo-server/migration-two-dot.html#request-headers

const apollo = new ApolloServer({
  typeDefs
  resolvers,
  context: ({ req }) => ({ req })
  engine: false
});

Solves it but got an issue with Cookie with token not getting to the browser.

NUS
  • 383
  • 1
  • 6
  • 17