question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Http headers] I need to send a cookie.

See original GitHub issue

How can I access to the response headers since this lib provides only the req parameter but not res ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

32reactions
helfercommented, Apr 18, 2016

You’re right, they’re not defined in the example I gave above, so it wouldn’t work. What you actually have to write is something like this (which wraps the graphqlHTTP middleware in a function that acts as middleware:

app.use('/graphql', (req, res) => {
  return graphqlHTTP({
    schema,
    graphiql: true, // or whatever you want
    context: { req, res },
  })(req, res);
);
27reactions
helfercommented, Apr 15, 2016

I’m not sure why you thought you had to fork the project to do this… the following should work:

app.use('/graphql', graphqlHTTP({
  schema,
  graphiql: true, // or whatever you want
  context: { req, res },
});

and in your resolve function:

resolve: (root, args, context) => {
  let cookieValue;
 /* your code here */
  context.res.set('cookie', cookieValue);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cookie - HTTP - MDN Web Docs
The Cookie HTTP request header contains stored HTTP cookies associated with the server (i.e. previously sent by the server with the ...
Read more >
HTTP headers | Cookie - GeeksforGeeks
HTTP headers are used to pass additional information with HTTP response or HTTP requests. A cookie is an HTTP request header i.e. used...
Read more >
How are cookies passed in the HTTP protocol? - Stack Overflow
Cookies are passed as HTTP headers, both in the request (client -> server), and in the response ...
Read more >
HTTP Headers and Cookies - YouTube
This video is part of the Passport JS User Authentication Series. To view the entire series as a playlist, click the link ...
Read more >
HTTP Cookies - Win32 apps | Microsoft Learn
The Set-Cookie header is sent by the server in response to an HTTP request, which is used to create a cookie on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found