我正在将我的代码从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。
发布于 2019-05-16 10:17:16
文档中有两个变量-- email和password。您实际传递给useMutation的是一个名为data的变量,该变量并不存在。
const variables = { email, password }https://stackoverflow.com/questions/56159612
复制相似问题