I have a express server in which I am using express-graphql. I am also authenticating with passport and passport-google-oauth20.
I am setting up my graphQl without the context:
router.use(graphqlHTTP({
schema,
graphiql: true
}));
Which means that the request is passed into my resolver as the context.
const rootResolvers = {
Query: {
hello: (obj, args, context) => {
console.log(context.headers.cookie);
return "hello"
}
}
};
I can see the cookie from the request. How do use the cookie that get to deserialize the user? passport typically does this for me, but in this case I need to call the deserialize function outside of the passport lifecycle. How do I do this?
There is a user attached to the request and it is already deserialized. Inside the resolver, all that needs to be done is access the user:
const rootResolvers = {
Query: {
hello: (obj, args, context) => {
console.log(context.user);
return "hellllo"
}
}
};
And now you can use it anyway that you want.