2017-05-18 21:21:33 +03:00
|
|
|
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
|
2017-06-01 12:28:59 +03:00
|
|
|
import { enableBatching } from 'redux-batched-actions';
|
2017-05-18 21:21:33 +03:00
|
|
|
import { ApolloClient, createNetworkInterface } from 'react-apollo';
|
|
|
|
import state from './state';
|
2017-06-01 12:28:59 +03:00
|
|
|
import { ui } from './reducers';
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-06-01 13:57:51 +03:00
|
|
|
const GQL_HOSTNAME =
|
|
|
|
process.env.REACT_APP_GQL_HOSTNAME || window.location.hostname;
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
export const client = new ApolloClient({
|
|
|
|
dataIdFromObject: o => {
|
|
|
|
const id = o.slug
|
|
|
|
? o.slug
|
|
|
|
: o.id
|
|
|
|
? o.id
|
|
|
|
: o.uuid
|
|
|
|
? o.uuid
|
|
|
|
: o.timestamp
|
|
|
|
? o.timestamp
|
|
|
|
: o.name ? o.name : 'apollo-cache-key-not-defined';
|
|
|
|
return `${o.__typename}:${id}`;
|
|
|
|
},
|
|
|
|
networkInterface: createNetworkInterface({
|
2017-06-01 13:57:51 +03:00
|
|
|
uri: `http://${GQL_HOSTNAME}:3000/graphql`
|
2017-05-18 21:21:33 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
export const store = createStore(
|
|
|
|
combineReducers({
|
2017-06-01 12:28:59 +03:00
|
|
|
ui,
|
2017-05-18 21:21:33 +03:00
|
|
|
apollo: client.reducer()
|
|
|
|
}),
|
2017-06-01 12:28:59 +03:00
|
|
|
state, // Initial state
|
2017-05-18 21:21:33 +03:00
|
|
|
compose(
|
|
|
|
applyMiddleware(client.middleware()),
|
|
|
|
// If you are using the devToolsExtension, you can add it here also
|
|
|
|
// eslint-disable-next-line no-negated-condition
|
|
|
|
typeof window.__REDUX_DEVTOOLS_EXTENSION__ !== 'undefined'
|
|
|
|
? window.__REDUX_DEVTOOLS_EXTENSION__()
|
|
|
|
: f => f
|
|
|
|
)
|
|
|
|
);
|