[英]GraphQL input type not found
我有一個用 Express / Apollo Server / GraphQL / MongoDB / Mongoose 和一個用 React 做的前端。
我有我想要進行突變和查詢的組件,我檢查了前端和后端之間的連接,這很好。
我在后端的突變:
createUser(input: SignupInput:): AuthUser!
input SignupInput {
name: String!
username: String!
email: String!
password: String!
}
AuthUser 返回的是一個用戶。 那有更多的領域,但我認為這不是必要的信息。
在我的前端
const NEW_USER = gql`
mutation CreateUser($type: SignupInput!) {
createUser(input: $type) {
user {
id
}
}
}
`;
const [newTest, { data }] = useMutation(NEW_USER);
const onSubmit = (formData) => {
newTest({
variables: {
name: formData.name,
username: formData.username,
email: formData.email,
password: formData.password,
},
});
};
錯誤 400 的網絡響應:
"Variable \"$type\" of required type \"SignupInput!\" was not provided."
我真的不明白為什么會這樣,我在其他人的代碼中看到,使用后端輸入類型的名稱創建變量是可行的。
如果我嘗試解構 SignInput:鍵入並寫入 {$name, .String。 .:.) 我得到這個錯誤:
Unknown argument \"name\" on field \"Mutation.createUser\".", locations: […], extensions: {…} }
newTest({
variables: {
input: {
name: formData.name,
username: formData.username,
email: formData.email,
password: formData.password,
}
},
});
輸入未在突變 function 中傳遞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.