简体   繁体   English

提供从GraphQL到Redux的数据

[英]Provide Data from GraphQL to Redux

I have project, where I use redux , react-apollo and I wonder, is any chance to provide data from react-apollo to redux through reducer. 我有一个项目,在这里我使用reduxreact-apollo ,我想知道是否有任何机会通过reducer提供从react-apolloredux数据。 Pseudo code below. 下面的伪代码。

 ... import { graphql } from 'react-apollo' import gql from 'graphql-tag' const query = gql` { ... }` /* Function, which I want to returns data from graphql */ const getDate = () => { return graphql(query) } /*---- Reducer ----*/ export default (state = getDate(), action) => { console.log(state) // function, instead data ... } 

Something like Apollo Link Redux might help. 诸如Apollo Link Redux之类的功能可能会有所帮助。 It's intended to provide backwards compatibility for Apollo Client v1.0 apps looking to migrate to v2.0. 旨在为希望迁移到v2.0的Apollo Client v1.0应用程序提供向后兼容性。 In short it will dispatch the following actions 简而言之,它将调度以下操作

APOLLO_QUERY_INIT
APOLLO_QUERY_RESULT
APOLLO_MUTATION_INIT
APOLLO_MUTATION_RESULT

which you can handle in your reducers. 您可以在减速器中处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM