我得到[GraphQL error]: Message: Validation failed for the field [login]., Location: [object Object], Path: login
,但我不太清楚问题出在哪里。我记录了凭据,但它们不为空。
该突变在graphql操场上也很好用,并且该错误不是真正的描述性错误,因此我无法弄清楚到底是什么错误。 该突变在graphql操场上也很好用,并且该错误不是真正的描述性错误,因此我无法弄清楚到底是什么错误。
这是代码
const Login = () => {
const [credentials, setCredentials] = useState({
email: null,
password: null,
user: null,
});
console.log(credentials);
const updateInput = (field, text) => {
setCredentials({ ...credentials, [field]: text });
};
const LOGIN = gql`
mutation Login($email: String!, $password: String!, $user: String!) {
login(email: $email, password: $password, user: $user) {
token
}
}
`;
const [login, { data }] = useMutation(LOGIN);
return (
<>
<View style={styles.container}>
<Header />
<View>
<Text>Login</Text>
<View>
<TextInput
placeholder="Email"
onChangeText={(text) => {
updateInput("email", text);
}}
/>
<TextInput
placeholder="Password"
onChangeText={(text) => {
updateInput("password", text);
}}
/>
<View>
<Picker
selectedValue={credentials.user}
onValueChange={(itemValue, itemIndex) =>
updateInput("user", itemValue)
}
>
<Picker.Item label="Select user type" />
<Picker.Item label="Patient" value="patient" />
<Picker.Item label="Doctor" value="doctor" />
</Picker>
</View>
<TouchableOpacity
onPress={() => {
return login({
variables: {
user: credentials.user,
email: credentials.email,
password: credentials.password,
},
})
.then((data) => console.log(data))
.catch((error) => console.log(error));
}}
>
<Text>Login</Text>
</TouchableOpacity>
</View>
</View>
</View>
</>
);
};
export default Login;