阿波罗:数据/突变道具未传递到组件 [英] Apollo: data / mutation prop not passed to component
本文介绍了阿波罗:数据/突变道具未传递到组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下带有查询和突变的组件,但我的组件未接收到数据和突变道具.
I have the following component with a query and a mutation, but my Component does not receive the data and the mutation prop.
我在代码中做错了什么吗?虽然查询确实得到执行,但它并未传递下来.尚未定义this.props.mutate和this.props.data.
Am I doing something wrong or missing in my code? The query does get executed though, it's just not passed down. this.props.mutate as well as this.props.data is undefined.
class ResetConfirm extends React.Component {
static propTypes = {
intl: intlShape.isRequired,
token: React.PropTypes.string,
data: React.PropTypes.shape({
loading: React.PropTypes.bool.isRequired,
checkToken: React.PropTypes.array,
}).isRequired,
mutate: React.PropTypes.func.isRequired,
}
submitForm = (model) => {
this.setState({
loading: true,
});
this.props.mutate({ variables: { password: model.password, token: this.props.token } })
.then(({ data }) => {
// redirect
}).catch((error) => {
console.log('there was an error sending the query', error);
});
}
render() {
//render jsx
}
}
const CheckTokenQuery = gql`
query CheckToken($token: String!) {
checkToken(token: $token) {
response
}
}
`;
const SetNewPasswordMutation = gql`
mutation SetNewPasswordMutation($password: String!, $token: String!) {
resetPassword(password: $password, token: $token) {
response
}
}
`;
export default graphql(SetNewPasswordMutation, { name: SetNewPasswordMutation })(
graphql(CheckTokenQuery, { name: CheckTokenQuery, forceFetch: true })(injectIntl(connect(ResetConfirm)))
);
推荐答案
您已使用name
命名了突变道具SetNewPasswordMutation
.
You have used name
to name the mutation prop SetNewPasswordMutation
.
这意味着您需要从组件中调用它,例如:
This means that you need to call it from your component like:
this.props.SetNewPasswordMutation(
{ variables: { password: model.password, token: this.props.token } })
这篇关于阿波罗:数据/突变道具未传递到组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文