如果我在我的应用程序中使用 redux 和 apollo 客户端,那么从组件外部的操作触发查询的最佳方法是什么。
例如,如果我有一个标准应用程序,配置了 redux 和 apollo 客户端,我应该如何触发“刷新”列表。我可以在具有 gql 的组件本身上触发一个函数,但是我将如何通过一个更符合通量的操作来执行它。
import React, { Component, PropTypes } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { connect } from 'react-redux';
import { refreshProfile } from './actions';
class Profile extends Component { ... }
Profile.propTypes = {
data: PropTypes.shape({
loading: PropTypes.bool.isRequired,
user: PropTypes.object,
}).isRequired,
};
const UserQuery = gql`
query getUser {
user {
id
name
}
}
`;
const ProfileWithData = graphql(UserQuery)(Profile);
const ProfileWithDataAndState = connect(
(state) => ({ user: state.user })),
)(ProfileWithData);
并且,假设我想触发一个动作来刷新用户数据?由于逻辑在组件本身中,我不确定如何从操作本身触发 gql 查询。