【问题标题】:Apollo Angular not sending requestApollo Angular 未发送请求
【发布时间】:2019-06-12 01:07:38
【问题描述】:

我有一个简单的查询(Apollo-Angular 客户端)从 GraphQL 服务器获取一些数据

  public getQuestionBank(courseCode: string): Observable<ApolloQueryResult<{}>> {
    const query = gql`
    query GetQuestionsQuery($courseCode: String!) {
      questions(courseCode: $courseCode) {
        questions
        status
      }
    }
  `;
  console.log(`GETTING QUESTIONS FOR: ${courseCode}`);
  return this.apollo.query({
    query: query,
    variables: {
      courseCode: courseCode
    },
    errorPolicy: 'all',
    context: {
      headers: new HttpHeaders().set('Authorization', this.user.Token)
    }
  });
}

console.log 被触发,但服务器从未收到请求 我使用类似类型的查询来登录,这很有效

  public login(email: string, password: string): Observable<ApolloQueryResult<{}>> {
    const query = gql`
    query TeacherLoginQuery($email: String!, $password: String!) {
      teacherLogin(email: $email, password: $password) {
        id
        email
        admin
        token
        name
        status {
          code
        }
      }
    }
  `;

  return this.apollo.query({
    query: query,
    variables: {
      email: email,
      password: password
    },
    errorPolicy: 'all',
  });
}

我在服务器上有一个摩根记录器,但没有收到任何请求

【问题讨论】:

  • 你有没有发现任何错误?
  • 你能检查一下你是否订阅了getQuestionBank()函数吗?
  • 我的订阅错误,所以如果订阅错误,我应该假设什么都不会从 observable 发出吗?

标签: node.js angular graphql apollo-client apollo-angular


【解决方案1】:

我遇到了同样的问题,重置客户端商店对我有用。

await this.apollo.client.resetStore();

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 2021-11-03
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多