使用redux observable管理react apollo

时间:2017-06-27 19:36:56

标签: reactjs redux react-apollo redux-observable

我想用redux observable管理我的提取,但我找不到任何例子。有人对此有答案吗?

通过apollo vanillaJS,这是获取查询结果的方法:

../../../../../../../etc/passwd

现在我需要在redux observable中插入它来管理答案:

const opts = {uri: 'http://localhost:8080/graphql'};
const networkInterface = createNetworkInterface(opts);
const client = new ApolloClient({
networkInterface});

let query = gql`query {
                    viewer {
                        id
                        firstName
                        lastName
                        defaultTimeZoneId
                        defaultLanguage
                    }
                }`;
client.query({query}).then((results) => {})
//return a promise

由于

1 个答案:

答案 0 :(得分:1)

您可以像这样使用运算符fromPromise

const fetchQuestionsEpic = action$ =>
  action$.ofType(FETCH_QUESTIONS)
  .mergeMap(() =>
    Observable.fromPromise(fetchQuestions())
      .map(questions => ({ type: QUESTIONS_FETCHED, questions })),
  );

此回购符合一些良好做法github.com/voteetvous