-
I'm trying to fetch client's ip address in one of my resolvers using the request object. I know Ip address something related to nginx proxy(I did that). basically I'm doing like this const ip = request.headers['x-forwarded-for'] ||
request.connection.remoteAddress ||
request.socket.remoteAddress ||
request.connection.socket.remoteAddress;
console.log(ip); But getting undefined or null. it seems to work earlier for yoga v1 but it is not working for yogav2. can u pls help me on this one |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In GraphQL Yoga. If you really want to access Node's See here to learn more about Yoga's context object; |
Beta Was this translation helpful? Give feedback.
In GraphQL Yoga.
request
object is aRequest
not Node'sIncomingMessage
so it doesn't haveconnection
orsocket
but it hasheaders
which is not a key-value object but more like a Map which is aHeaders
withget
andset
methods.If you really want to access Node's
IncomingMessage
, you can get it fromcontext.req
instead ofcontext.request
which is available only in@graphql-yoga/node
& Node.js environment.See here to learn more about Yoga's context object;
https://www.graphql-yoga.com/docs/features/context