Appsync + Angular:未调用订阅

时间:2018-11-28 20:26:03

标签: angular graphql subscription aws-appsync aws-amplify

我无法进行订阅。

我做了什么:

我按照说明配置了API as_tibble docs

API.ts

export type UpdateProjectInput = {
  project_name: string,
  uniq_id: string,
  brand_name?: string | null,
  emails?: string | null,
  head_line?: string | null,
};

mutations.ts

export const updateProject = `mutation UpdateProject($input: UpdateProjectInput!) {
  updateProject(input: $input) {
    project_name
    uniq_id
    brand_name
    emails
    head_line
  }
}
`;

subscription.ts

export const onUpdateProject = `subscription OnUpdateProject(
  $project_name: String
  $uniq_id: String
  $brand_name: String
  $emails: String
  $head_line: String
) {
  onUpdateProject(
    project_name: $project_name
    uniq_id: $uniq_id
    brand_name: $brand_name
    emails: $emails
    head_line: $head_line
  ) {
    project_name
    uniq_id
    brand_name
    emails
    head_line
  }
}
`;

test.service.ts

const client = new AWSAppSyncClient({
  url: aws_config.aws_appsync_graphqlEndpoint,
  region: aws_config.aws_appsync_region,
  auth: {
    type: AUTH_TYPE.API_KEY,
    apiKey: aws_config.aws_appsync_apiKey,
  }
});

subscibeData() {
    let subscription;
    (async () => {
      subscription = client.subscribe({ query: gql(onUpdateProject) }).subscribe({
        next: data => {
          console.log("Update.");
          console.log(data.data);
        },
        error: error => {
          console.warn(error);
        }
      });
    })();

    setTimeout(() => {
      subscription.unsubscribe();
    }, 60000);
  }

在我的应用中,我首先运行this.testService.subscibeData();,然后在GraphQL游乐场中运行突变以更新dynamo数据库中的数据。我检查了dynamo数据库,数据已更新=>突变正确,但是没有订阅日志。似乎在执行突变后未调用该订阅。

任何建议都值得赞赏

0 个答案:

没有答案