this.props.login 不是函数 react-apollo + compose + graphql
this.props.login is not a function react-apollo + compose + graphql
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 is not a function。
好吧,基本上你是在触发一个查询,但称之为突变。
你必须为查询交换变异,所以它看起来像这样:
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'
}),
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 is not a function。
好吧,基本上你是在触发一个查询,但称之为突变。
你必须为查询交换变异,所以它看起来像这样:
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'
}),