Send a Cookie header field in relay request

2020-07-27 03:09发布

问题:

It looks like stock relay networklayer does'nt send a cookie header field with his request. So I tried to add it by adding Cookie field like this:

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('/graphql', {
    headers: {
      'Cookie': 'user=thibaut',
    },
  })
);

but still the Cookie field is not present in my post request. If I replace 'Cookie' with 'Set-Cookie', IT IS in my post request...

I need my server to use cookies please help ! :)

回答1:

Set your cookies in the usual way (using browser APIs) then configure fetch as follows to have them sent along with each request:

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('/graphql', {
    credentials: 'same-origin',
  })
);

See also: https://github.com/facebook/relay/issues/437



标签: relayjs