简体   繁体   中英

Unit Test GraphQL schemas/queries made in AWS AppSync?

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

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

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.

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

  1. Create a Lambda function which runs on a schedule. This lambda function will make various GraphQL requests. It can emit success/failure metrics to CloudWatch.
  2. Setup a CloudWatch alarm so you can be notified if your success/failure metric is out of the ordinary.

For the canary use-case see:

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

There is also amplify amplify-appsync-simulator package that is supposed to help with testing appsync, but there is no documentation on how you should use it. It is used by serverless-appsync-simulator Michael wrote and Amplify itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM