我尝试使用Apollo的usemutation(),但是我不能很好地传递变量。 这是我的代码。
import { useMutation, gql } from '@apollo/client';
const CREATE_USER = gql(/* GraphQL */ `
mutation createUserByEmail($hoge: String!) {
createUserByEmail(input: $hoge) {
age
}
}
`);
const [createUser, { loading, error, data }] = useMutation(CREATE_USER);
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
const response = await createUser({variables: {hoge: 'hoge'}}) ;
}
我得到这样的错误
Argument type {variables: {hoge: string}} is not assignable to parameter type MutationFunctionOptions<any, OperationVariables, DefaultContext, ApolloCache<any>> | undefined
但是,我的代码与Apollo 的文档完全相同。 我的代码哪里错了?
非常感谢任何帮助。 最好的, 和也
您需要从代码生成器自动生成的文件中导入
gql
助手。