gpt4 book ai didi

amazon-web-services - 使用 RDS 后端修改 AWS Amplify 中的解析器

转载 作者:行者123 更新时间:2023-12-03 17:25:57 24 4
gpt4 key购买 nike

将 AWS Amplify 与 dynamodb 后端一起使用时,可以通过在本地修改文件然后执行 amplify push 来更新 AppSync 架构和解析器。 .

我正在使用 RDS(如文档中所述,使用 amplify api add-graphql-datasource 添加它)。查询和解析器会自动在 AppSync 中设置。当我更新 Aurora RDS 架构时,我运行 amplify api add-graphql-datasource再次更新查询和解析器。

但是如何使用放大 CLI 添加新的查询/突变并将它们绑定(bind)到新的解析器(在本地主机上的 vtl 文件中定义)?

我想出了如何使用 AppSync Web 控制台来做到这一点。我在 AppSync 中修改架构并创建解析器,然后使用 amplify codegen更新 App.ts , queries.ts等。但是,这种方法至少有两个原因是不好的。

  • 在使用多个环境时,必须通过 AppSync 控制台手动更改每个环境,这对于大型项目来说是困难的。
  • amplify codegen不更新 schema.graphql本地主机上的文件。
  • 执行amplify push在对 AppSync 进行更改后,使用 localhost 上定义的架构并覆盖 AppSync 控制台中定义的架构。
  • app/amplify/backend/<backend_name>/resolvers 中的自定义解析器未与 AppSync
  • 同步
  • 堆栈文件不会自动更新。

  • 我会以错误的方式解决这个问题吗?在使用 RDS 后端时,是否有更好的方法来使用 Amplify CLI 更新架构/解析器?

    谢谢!

    最佳答案

    好的,

    1. When working with multiple environments, changes to each environment has to be done manually via the AppSync console, which isdifficult for larger projects.

    为每个环境保留一个 git 分支。首先在 dev 中进行更改分支并运行 amplify push将更改推送到 AppSync dev项目。当需要将更改引入暂存时,请执行以下操作:
  • cd app && amplify env checkout staging && amplify env pull --restore && amplify status
  • git checkout staging && git merge dev
  • amplify push

    1. amplify codegen doesn't update the schema.graphql file on localhost.

    是的,但不是 amplify codegen应该这样做,所以我不确定我写的是什么。文档很清楚:

    Codegen helps you generate native code for iOS and Android, as well asthe generation of types for Flow and TypeScript. It can also generateGraphQL statements (queries, mutations, and subscriptions) so that youdon’t have to hand code them.


    ..下一个!
    1. Executing amplify push after making changes to AppSync over uses theschema defined on localhost and overwrites the schema defined in theAppSync console.I'm not sure what I meant to say here. But the workflow that ended up working for me is

  • 更新 schema.graphql在本地主机上
  • 在 localhost
  • 上创建解析器文件
  • amplify push更新 AppSync

    1. Custom resolvers in app/amplify/backend/<backend_name>/resolvers arenot synchronized with AppSync

    我错了。如果您正确创建所需的解析器文件,则 AppSync 解析器在运行时会正确配置 amplify push .我的错误是我忘记创建响应映射器模板文件。
    1. the stack file is not updated automatically.

    这是真的,但您很快就会习惯手动编辑堆栈文件。确实,如果有一个快速添加功能会很好,但因为您只是添加一个 json文件,很容易拼凑一个快速的python脚本来为你做这件事。

    关于amazon-web-services - 使用 RDS 后端修改 AWS Amplify 中的解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60942850/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com