首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apollo GraphQL和React等同于redux-logger

Apollo GraphQL和React等同于redux-logger
EN

Stack Overflow用户
提问于 2017-02-24 06:59:26
回答 1查看 536关注 0票数 0

我正在学习graphql,我想知道是否有针对apollo-client的日志记录解决方案。

我发现redux-logger是一个调试React/Redux应用程序的强大工具,我想知道appolo-client是否存在类似的工具?

我想要查看我的store在任何给定时间的状态。

EN

回答 1

Stack Overflow用户

发布于 2017-02-24 08:33:18

好吧,我想我应该多研究一下。

这里有一个很好的解释:http://dev.apollodata.com/react/redux.html#creating-a-store

如果有人对此感兴趣,这就是我用redux-logger实现apollo-client的方式。

代码语言:javascript
复制
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')
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42427798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档