【问题标题】:How to retrieve the schema.graphql file from @aws-cdk/aws-appsync before deployment如何在部署前从@aws-cdk/aws-appsync 检索 schema.graphql 文件
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      我最终使用 aws-cli 通过以下命令提取 appsync 架构:

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

      【讨论】:

      • 不是同一个问题。为了在我的客户端应用程序中同步架构,我使用了放大。
      猜你喜欢
      • 2022-10-22
      • 1970-01-01
      • 2020-08-23
      • 2020-05-08
      • 2019-11-12
      • 2020-11-23
      • 2020-08-15
      • 2021-05-08
      • 2020-10-07
      相关资源
      最近更新 更多