React-apollo: Redux Store

Created on 28 Nov 2017  路  6Comments  路  Source: apollographql/react-apollo

Intended outcome:
Use ApolloClient as redux store provider for ConnectedRouter.

import store, { history } from './store';
import App from './containers/app';

const target = document.querySelector('#root');
const client = new ApolloClient({
  link: new HttpLink({ uri: 'http://localhost:3001/graphql' }),
  cache: new InMemoryCache(),
});
render(
  <ApolloProvider store={store} client={client} >
    <ConnectedRouter history={history}>
      <App />
    </ConnectedRouter>
  </ApolloProvider>,
  target,
);

Actual outcome:
ConnectedRouter from https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux is incompatible with <ApolloProvider>. It seems that the documentation available at here seems to indicate you can pass a store prop to ApolloClient but this doesn't appear to be implemented.. This was also reported as https://github.com/ReactTraining/react-router/issues/5736.

How to reproduce the issue:
Check latest master https://github.com/apollographql/react-apollo/blob/master/src/ApolloProvider.tsx#L37-L41 and see that there is no store prop. The documentation should be updated to indicate the recommended way to use ApolloProvider with Redux Provider.

Version

Most helpful comment

Yes. Meanwhile, I guess you could do that:

<ApolloProvider client={client}>
    <Provider store={store}>
        <MyApp />
    </Provider>
</ApolloProvider>

All 6 comments

Did you try [email protected]?

I can confirm it used to work in older versions. But after upgrading to 2.x it seems it no longer works. You need to use the stock provider from react-redux

Confirmed regression from [email protected].

Yes. Meanwhile, I guess you could do that:

<ApolloProvider client={client}>
    <Provider store={store}>
        <MyApp />
    </Provider>
</ApolloProvider>

Any idea when this will be fixed? Not sure why this was closed. Still an issue with version 2.1.3. @jmaylin, thanks for the workaround.

ApolloProvider simply provides the client provided through the react context, and apollo is no longer redux based. Therefore there is no store option here anymore.

Was this page helpful?
0 / 5 - 0 ratings