我的组件文件中的登录功能
logIn() {
this._userServices
.login(this.signInForm.value)
.then((result: any) => {
console.log('result', result);
// localStorage.setItem('accessToken', result.data.login.token);
// localStorage.setItem('userId', result.data.login.userId);
// const redirectURL =
// this._activatedRoute.snapshot.queryParamMap.get(
// 'redirectURL'
// ) || '/signed-in-redirect';
// Navigate to the redirect url
// this._router.navigateByUrl(redirectURL);
})
.catch((err) => {
console.log(err);
});
}
带有登录功能的我的服务文件,包括对 Apollo GraphQl 的查询
login = (value) => {
return new Promise((resolve, reject) => {
this.apollo
.mutate({
mutation: this.User_Login,
variables: {
email: value.email,
password: value.password,
},
})
.subscribe(
(result) => {
console.log(result);
resolve(result);
},
(error) => {
reject(error);
}
);
});
};
这是我使用 Apollo Studio 成功测试的 GraphQL 查询
public User_Login = gql`
mutation Mutation($email: String, $password: String) {
login(email: $email, password: $password) {
token
userId
}
}
`;
我收到的错误消息
ApolloError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
我已经测试了来自 Apollo studio 的查询并获得了数据。当我通过 Angular 前端请求时出现此错误。但是我成功地将我的其他服务与我的后端连接起来,这没有问题。但是当我尝试将登录功能与我的后端连接时,这是我遇到的错误。我是如何解决这个问题的,我不知道错误是从哪里来的。