GraphQL, Apollo, React and Redux

Albert
Albert
Oct 12, 2017 · 1 min read

I love GraphQL is very simple and easy (Thank FB).

In this post I just will work with the DEVICE table.

Tables of my project

So simple, the code GraphQL, Apollo and React is here:

GraphQL, Apollo and React

If you want add Redux, just need change the last line (line 58) to this:

const mapStateToProps = state => ({  });
const mapDispatchToProps = (dispatch) => {
return {}
}
export default compose(
graphql(deleteDevice),
graphql(devices),
connect(mapStateToProps, mapDispatchToProps)
)(Devices);

And in the index.js you must have the configuration to redux and graphQL

const networkInterface = createNetworkInterface({
uri: 'http://localhost:8000/graphql',
});
const client = new ApolloClient({ networkInterface });
const reducerDevices = (state = [], action) => {
return state;
}
const reducers = combineReducers({
apollo: client.reducer(),
devices: reducerDevices
});
const store = createStore(
reducers,
{},
compose(
applyMiddleware(client.middleware()),
(typeof window.__REDUX_DEVTOOLS_EXTENSION__ !== 'undefined') ? window.__REDUX_DEVTOOLS_EXTENSION__() : f => f,
)
);
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store