如何在部署前从@aws-cdk/aws-appsync检索schema.graphql文件



我在@aws-cdk/aws-appsync中使用代码优先的方法来生成我的graphql模式。为了生成Typescript代码,我需要一种在部署之前检索schema.graphql的方法(也许是从cdk synth命令中提取它?(。

我不确定我们是否面临同样的问题。基本上,我想访问我的客户端react应用程序中的GQL模式,该应用程序与定义基础设施的cdk应用程序位于不同的存储库中。

我最终使用aws-cli使用以下命令提取appsync模式:

aws appsync get-introspection-schema --api-id [API-ID] --format SDL --no-include-directives outfile=[OUTFILE]

要在部署前获得自动创建的架构,请使用以下脚本:

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;
});
});

最新更新