【发布时间】:2020-01-10 11:17:59
【问题描述】:
我在这里使用 express graphql 和 apollo 客户端。我面临一个突变问题
.................................................. ..................................................... ......................
我的错误:
[GraphQL 错误]:消息:字段上的未知参数“电子邮件” “rootMutation”类型的“createUser”,位置:[object Object],路径: 未定义
当我点击注册按钮时,它给了我一个错误。 我的组件:
import { useMutation } from "@apollo/react-hooks";
import { gql } from "apollo-boost";
const CREATE_USER = gql`
mutation createUser($email: String!, $password: String) {
createUser(email: $email, password: $password) {
_id
email
}
}
`;
function Register() {
const [email, setEmail] = React.useState("");
const [password, setPassword] = React.useState("");
const [createUser, { data }] = useMutation(CREATE_USER);
return (
<div class="row">
<div class="input-field col s12">
<input
id="email"
type="text"
class="validate"
onChange={e => setEmail(e.target.value)}
/>
<label for="email"> Email </label>
</div>
<div class="input-field col s12">
<input
id="password"
type="password"
class="validate"
onChange={e => setPassword(e.target.value)}
/>
<label for="password"> Password</label>
</div>
<button
className="btn"
onClick={() => {
createUser({
variables: { $email: email, $password: password }
});
console.log(data);
}}
>
Register
</button>
</div>
);
}
export default Register;
我的架构:
``` type User {
email: String!,
password: String,
createdEvents:[Event!]
}
type rootMutation {
createUser(userInput: UserInput): User,
}```
【问题讨论】:
-
你能在你的架构中显示你的 UserInput 类型吗?
-
为什么是负面的?...