【发布时间】:2019-10-03 04:53:49
【问题描述】:
我正在将我的代码从 apollo-boost 重构为 react-apollo-hooks,但我不断收到以下错误:
Variable "$email" of required type "String!" was not provided
Variable "$password" of required type "String!" was not provided
我的重构代码如下:
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const variables = {
data: { email, password }
}
const login = useMutation(LOGIN_MUTATION, {
variables
})
const onSubmitHandler = async (login, e) => {
e.preventDefault()
const authResults = await login()
localStorage.setItem(AUTH_TOKEN, authResults.data.login.token);
props.history.push('/')
}
graphql 突变
const LOGIN_MUTATION = gql`
mutation Login($email: String!, $password: String!) {
login(data: {
email: $email, password: $password
}
){
token
user {
id
}
}
}
`
我的架构
login(data: LoginUserInput!): AuthPayload!
console.logging 电子邮件和密码变量表明它们已正确传递给useMutation。
【问题讨论】:
标签: reactjs graphql apollo react-apollo