2017-05-18 21:21:33 +03:00
|
|
|
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
|
2017-06-09 07:26:25 +03:00
|
|
|
import { reducer as formReducer } from 'redux-form';
|
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-07-26 17:28:14 +03:00
|
|
|
const GLOBAL =
|
|
|
|
typeof window === 'object'
|
|
|
|
? window
|
|
|
|
: {
|
|
|
|
location: {
|
|
|
|
hostname: '0.0.0.0'
|
|
|
|
}
|
|
|
|
};
|
2017-06-06 16:30:43 +03:00
|
|
|
|
2017-08-02 01:38:20 +03:00
|
|
|
const GQL_PORT = process.env.REACT_APP_GQL_PORT || 443;
|
2017-08-08 13:07:18 +03:00
|
|
|
const GQL_HOSTNAME =
|
|
|
|
process.env.REACT_APP_GQL_HOSTNAME || GLOBAL.location.hostname;
|
2017-08-02 01:38:20 +03:00
|
|
|
const GQL_PROTOCOL = process.env.REACT_APP_GQL_PROTOCOL || 'https';
|
2017-06-01 13:57:51 +03:00
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
export const client = new ApolloClient({
|
|
|
|
dataIdFromObject: o => {
|
|
|
|
const id = o.slug
|
|
|
|
? o.slug
|
|
|
|
: o.id
|
2017-06-09 07:26:25 +03:00
|
|
|
? o.id
|
|
|
|
: o.uuid
|
|
|
|
? o.uuid
|
|
|
|
: o.timestamp
|
|
|
|
? o.timestamp
|
2017-08-22 18:24:49 +03:00
|
|
|
: o.name && o.instance
|
|
|
|
? `${o.name}-${o.instance}`
|
|
|
|
: o.name ? o.name : o.time && o.value
|
|
|
|
? `${o.time}-${o.value}` : 'apollo-cache-key-not-defined';
|
2017-05-18 21:21:33 +03:00
|
|
|
return `${o.__typename}:${id}`;
|
|
|
|
},
|
|
|
|
networkInterface: createNetworkInterface({
|
2017-08-02 01:38:20 +03:00
|
|
|
uri: `${GQL_PROTOCOL}://${GQL_HOSTNAME}:${GQL_PORT}/api/graphql`
|
2017-05-18 21:21:33 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
export const store = createStore(
|
|
|
|
combineReducers({
|
2017-06-01 12:28:59 +03:00
|
|
|
ui,
|
2017-06-09 07:26:25 +03:00
|
|
|
apollo: client.reducer(),
|
|
|
|
form: formReducer
|
2017-05-18 21:21:33 +03:00
|
|
|
}),
|
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
|
2017-06-06 16:30:43 +03:00
|
|
|
typeof GLOBAL.__REDUX_DEVTOOLS_EXTENSION__ !== 'undefined'
|
|
|
|
? GLOBAL.__REDUX_DEVTOOLS_EXTENSION__()
|
2017-05-18 21:21:33 +03:00
|
|
|
: f => f
|
|
|
|
)
|
|
|
|
);
|