Created
March 27, 2017 01:14
-
-
Save guzmonne/8c52e1b0dfa3bd3aed6689a6ca881fca to your computer and use it in GitHub Desktop.
Redux and Apollo coniguration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------- | |
// Apollo Client Configuration | |
// --------------------------- | |
import {ApolloClient, createNetworkInterface} from 'react-apollo' | |
export const client = new ApolloClient({ | |
networkInterface: createNetworkInterface({ | |
addTypename: true, | |
dataIdFromObject: (result) => ( | |
result._id && result.__typename | |
? result.__typename + result._id | |
: null | |
), | |
uri: 'http://localhost:3000/graphql' | |
}) | |
}) | |
// ------------------ | |
// Main reducers file | |
// ------------------ | |
import {createStore, applyMiddleware, compose} from 'redux' | |
import thunk from 'redux-thunk' | |
import rootReducer from './reducers.js' | |
import {client} from './apollo.js' | |
const configureStore = preloadedState => { | |
const composeEnhancers = ( | |
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose | |
) | |
const store = createStore( | |
rootReducer, | |
preloadedState, | |
composeEnhancers( | |
applyMiddleware(client.middleware(), thunk) | |
) | |
) | |
if (module.hot) { | |
// Enable Webpack hot module replacement for reducers. | |
module.hot.accept('./reducers.js', () => { | |
const nextRootReducer = require('./reducers.js').default | |
store.replaceReducer(nextRootReducer) | |
}) | |
} | |
return store | |
} | |
export default configureStore | |
// ----------------------- | |
// configureStore function | |
// ----------------------- | |
import {createStore, applyMiddleware, compose} from 'redux' | |
import thunk from 'redux-thunk' | |
import rootReducer from './reducers.js' | |
import {client} from './apollo.js' | |
const configureStore = preloadedState => { | |
const composeEnhancers = ( | |
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose | |
) | |
const store = createStore( | |
rootReducer, | |
preloadedState, | |
composeEnhancers( | |
applyMiddleware(client.middleware(), thunk) | |
) | |
) | |
if (module.hot) { | |
// Enable Webpack hot module replacement for reducers. | |
module.hot.accept('./reducers.js', () => { | |
const nextRootReducer = require('./reducers.js').default | |
store.replaceReducer(nextRootReducer) | |
}) | |
} | |
return store | |
} | |
export default configureStore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment