Apollo-client: [apollo-boost] Ignores `fetchOptions.credentials`

Created on 4 Apr 2018  ·  12Comments  ·  Source: apollographql/apollo-client

Intended outcome:

Have credential being included with GraphQL request across different domains.

Actual outcome:

Credentials aren't included.

How to reproduce the issue:

import ApolloClient from 'apollo-boost'; 

const client = new ApolloClient({
  fetchOptions: {
    credentials: 'include',
  },
  uri: GRAPHQL_URI,
});

Version

  • "apollo-boost": "^0.1.3"

Credentials value is hardcoded over here
https://github.com/apollographql/apollo-client/blob/master/packages/apollo-boost/src/index.ts#L77

I submitted a PR at #3264

Most helpful comment

You can manually configure the client using the sample below:

import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: new HttpLink({
    credentials: 'include',
    uri: GRAPHQL_URI,
  }),
});

All 12 comments

You can manually configure the client using the sample below:

import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: new HttpLink({
    credentials: 'include',
    uri: GRAPHQL_URI,
  }),
});

I have the same problem.

Same here.

const client = new ApolloClient({
  cache: new InMemoryCache(),
  uri: 'http://localhost:4000/graphql',
  request: async operation => {
    operation.setContext({
      fetchOptions: {
        credentials: 'include'
      }
    });
  }
});

Here is my solution.

Why does the author not give priority to this bug?

@alexgorbatchev @haflinger thank you! Spent a lite too mutch time before I found this issue. Two days I'm not getting back 😅

whew- thank you for this - just spent the last hour trying to find out why cookies were not being sent :)

@wesbos i submitted a PR with this issue #3264

I'm hitting this bug as well where the client I've constructed using apollo-boost is not passing along the fetchOptions and the needed credentials. I'm using the solution that @haflinger suggested.

I'm using "apollo-boost": "^0.1.7".

Hi all - this has been fixed by https://github.com/apollographql/apollo-client/pull/3098, and has been merged in. It will be included in our next release (this upcoming Tuesday, June 12th). Thanks!

@hwillson I am using "apollo-client": "^2.4.7", with "apollo-boost": "^0.1.22",. This issue is still here.

Using Appllo boost doesn't work, but apollo-client works as normal

export const client = new ApolloBoostClient({
  uri: process.env.SERVER_ADDRESS || 'http://localhost:8080/api/graphql',
  fetchOptions: {
    credentials: 'include',
  },
});

`` export const client = new ApolloClient({ link: createHttpLink({ credentials: 'include', uri: 'http://localhost:8080/api/graphql', }), cache: new InMemoryCache(), });

Was this page helpful?
0 / 5 - 0 ratings