我正在学习graphql,我想知道是否有针对apollo-client的日志记录解决方案。
我发现redux-logger是一个调试React/Redux应用程序的强大工具,我想知道appolo-client是否存在类似的工具?
我想要查看我的store在任何给定时间的状态。
发布于 2017-02-24 08:33:18
好吧,我想我应该多研究一下。
这里有一个很好的解释:http://dev.apollodata.com/react/redux.html#creating-a-store
如果有人对此感兴趣,这就是我用redux-logger实现apollo-client的方式。
import React from 'react';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import createLogger from 'redux-logger';
import promise from 'redux-promise';
import ReactDOM from 'react-dom';
import ApolloCient from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
import reducers from './reducers';
import App from './App';
// Instantiate Apollo Client
const client = new ApolloCient();
// declare the redux-logger
const logger = createLogger({
collapsed: true,
diff: true,
});
const store = createStore(
combineReducers({
apollo: client.reducer(), // apollo reducer
reducers, // your others reducers
}),
{},
compose(
// apply client.middleware() from ApolloClient and logger from redux-logger
applyMiddleware(client.middleware(), thunk, promise, logger),
// If you are using the devToolsExtension, you can add it here also
// window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
)
);
const Root = () => {
return (
// pass redux store and apollo client to ApolloProvider
<ApolloProvider store={store} client={client}>
<App />
</ApolloProvider>
);
};
ReactDOM.render(
<Root />,
document.querySelector('#root')
);https://stackoverflow.com/questions/42427798
复制相似问题