Skip to content

Instantly share code, notes, and snippets.

@guzmonne
Created March 27, 2017 01:14
Show Gist options
  • Save guzmonne/8c52e1b0dfa3bd3aed6689a6ca881fca to your computer and use it in GitHub Desktop.
Save guzmonne/8c52e1b0dfa3bd3aed6689a6ca881fca to your computer and use it in GitHub Desktop.
Redux and Apollo coniguration
// ---------------------------
// 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