import { graphql, compose } from 'react-apollo'
import gql from 'graphql-tag'
const AUTHENTICATE_USER_MUTATION = gql`
query authenticateUserMutation($email: String!, $password: String!) {
login(email: $email, password: $password) {
token
}
}
`
const LOGGED_IN_USER_QUERY = gql`....`
export default compose(
graphql(AUTHENTICATE_USER_MUTATION, {
name: 'authenticateUserMutation',
options: (props) => ({
variables: { email: props.email,
password: props.password }
})
}),
graphql(LOGGED_IN_USER_QUERY, {
name: 'loggedInUserQuery',
options: { fetchPolicy: 'network-only' }
})
)(withRouter(Login))
点击登录功能后输入电子邮件和密码
OnclickLogin = async () => {
const { email, password } = this.state
await this.props.authenticateUserMutation({variables: {email, password}})
}
它给出错误 this.props.authenticateUserMutation 不是一个函数。
答案 0 :(得分:2)
好吧,基本上,您是在触发查询,但称它为变异。
您必须交换突变以进行查询,因此它看起来像这样:
const AUTHENTICATE_USER_MUTATION = gql`
mutation authenticateUserMutation($email: String!, $password: String!) {
login(email: $email, password: $password) {
token
}
}
`
,在底部不需要选项。如果要触发查询,则需要它们。
export default compose(
graphql(AUTHENTICATE_USER_MUTATION, {
name: 'authenticateUserMutation'
}),