本文介绍了在 AWS AppSync 中进行单元测试 GraphQL 架构/查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题:有没有办法/程序/方法来创建单元测试来测试在 AWS AppSync 上生成的 API Url 以验证创建的 GraphQL 架构、查询、突变等的有效性?

I have a simple question: is there a way/program/method to create unit tests to test the API Url generated on AWS AppSync to verify the validity of created GraphQL schemas, queries, mutations, etc?

推荐答案

有一个开源 AppSync Serverless 插件,它具有离线模拟器支持.您可能会发现它很有用:https://github.com/sid88in/serverless-appsync-plugin#offline-support

There is an open-source AppSync Serverless plugin which has offline emulator support. You may find it useful: https://github.com/sid88in/serverless-appsync-plugin#offline-support

另一个好的建议是拥有两个独立的 AppSync API.一个 API 托管您的生产流量.另一种是在更改投入生产之前对其进行测试.如果您使用 Cloudformation(强烈推荐)来管理您的基础架构,这会容易得多.

Another good recommendation is to have two separate AppSync APIs. One API is hosting you production traffic. The other is to test changes before they go to production. This is significantly easier if you use Cloudformation (highly recommended) to manage your infrastructure.

如果您想验证您的 API 是否定期(每分钟左右)工作,您可以创建如下所示的金丝雀:

If you want to validate your API is working periodically (every minute or so), you could create a canary like the following:

  1. 创建一个按计划运行的 Lambda 函数.这个 lambda 函数将发出各种 GraphQL 请求.它可以向 CloudWatch 发送成功/失败指标.
  2. 设置 CloudWatch 警报,以便在成功/失败指标异常时通知您.

有关金丝雀用例,请参阅:

For the canary use-case see:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.htmlhttps://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html

这篇关于在 AWS AppSync 中进行单元测试 GraphQL 架构/查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 12:21