【发布时间】:2021-01-07 15:35:52
【问题描述】:
我正在使用 code-first approach in @aws-cdk/aws-appsync 来生成我的 graphql 架构。出于 Typescript 代码生成的目的,我需要一种在部署之前检索 schema.graphql 的方法(可能以某种方式从 cdk synth 命令中提取它?)。
【问题讨论】:
标签: amazon-web-services graphql aws-appsync aws-cdk
我正在使用 code-first approach in @aws-cdk/aws-appsync 来生成我的 graphql 架构。出于 Typescript 代码生成的目的,我需要一种在部署之前检索 schema.graphql 的方法(可能以某种方式从 cdk synth 命令中提取它?)。
【问题讨论】:
标签: amazon-web-services graphql aws-appsync aws-cdk
要在部署前获取自动创建的架构,请使用以下脚本:
readFile('cdk.out/<YOUR-APP-NAME>.template.json', 'utf8', (err, data) => {
if (err) {
throw err;
}
const definition = JSON.parse(data)
.Resources
.<YOUR-SCHEMA-ID> // replace with your schema id
.Properties
.Definition;
writeFile('lib/domain/generated.graphql', definition, (error) => {
if (error) throw error;
});
});
【讨论】:
我不确定我们是否面临同样的问题。基本上我想在我的客户端 react 应用程序中访问 GQL 模式,该应用程序与定义基础设施的 cdk 应用程序位于不同的存储库中。
我最终使用 aws-cli 通过以下命令提取 appsync 架构:
aws appsync get-introspection-schema --api-id [API-ID] --format SDL --no-include-directives outfile=[OUTFILE]
【讨论】: