Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 来自react apollo hooks的UseCommutation未传递变量_Reactjs_Graphql_Apollo_React Apollo - Fatal编程技术网

Reactjs 来自react apollo hooks的UseCommutation未传递变量

Reactjs 来自react apollo hooks的UseCommutation未传递变量,reactjs,graphql,apollo,react-apollo,Reactjs,Graphql,Apollo,React Apollo,我正在将我的代码从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, se

我正在将我的代码从
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电子邮件和密码变量表明它们被正确地传递到
use

文档中有两个变量--
电子邮件
密码
。实际上,您要传递给
usemotation
的是一个名为
data
的变量,它不存在

const variables = { email, password }