How can I get the data from GraphQL/Apollo in my Redux store ? Here is my entry file.
...
render(
(
<ApolloProvider client={client}>
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>
</ApolloProvider>
),
document.getElementById('root'),
);
And here is the store
import { createStore, applyMiddleware, compose as composeRedux } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import thunk from 'redux-thunk';
import createHistory from 'history/createBrowserHistory';
import rootReducer from '../reducers';
export const history = createHistory();
const initialState = {};
const enhancers = [];
const middleware = [
thunk,
routerMiddleware(history),
];
if (process.env.NODE_ENV === 'development') {
const { devToolsExtension } = window;
if (typeof devToolsExtension === 'function') {
enhancers.push(devToolsExtension());
}
}
const composedEnhancers = composeRedux(
applyMiddleware(...middleware),
...enhancers,
);
const store = createStore(
rootReducer,
initialState,
composedEnhancers,
);
export default store;
I used the following query for my App component
const LOGGED_IN_USER = gql`
query LoggedInUser {
loggedInUser {
id
facebookUserId
facebookEmail
facebookName
facebookPicture
facebookLocation
}
}
`;
export default compose(graphql(LOGGED_IN_USER, {
options: {
fetchPolicy: 'network-only',
},
}))(App);
Should I move the query from App to the store? I'm lost. ;-)