GraphQL, Apollo, React and Redux

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,
)
);