【问题标题】:AWS AppSync Update SchemaAWS AppSync 更新架构
【发布时间】:2019-12-11 13:29:09
【问题描述】:

我正在使用 AWS AppSync Web 控制台,我从头开始创建了一个新 API。

我创建了一个这样的新资源:

type ToDo {
  id: ID!
  title: String!
}

AWS AppSync 创建 DynamoDB 表和架构后,如果我想更新架构并添加新字段该怎么办?

type ToDo {
  id: ID!
  title: String!
  completed: Boolean
}

我知道 AWS Amplify 有一个命令 amplify api gql-compile,然后是 amplify push,它将更新架构和 DynamoDB 表。

有没有办法通过 AWS AppSync web console 做到这一点?

【问题讨论】:

  • 我相信你只是想在 web 控制台中简单地编辑和保存
  • 正确,我想简单地编辑、保存和生成新的突变、查询和从网络更新数据库表。
  • @AbeEstrada 你找到解决方案了吗?
  • @atlascoder 还没有,但也许新的Admin 是我需要的,但我需要看看
  • @AbeEstrada 谢谢,管理员对我来说是新功能

标签: amazon-web-services graphql aws-amplify aws-appsync


【解决方案1】:

如果您使用 AWS AppSync 控制台向导来创建它。您需要执行以下操作:

type ToDo {
    id: ID!
    title: String
    completed: Boolean # add here
}

input UpdateToDoInput {
    id: ID!
    title: String
    completed: Boolean # add here
}

input CreateToDoInput {
    title: String
    completed: Boolean # add here
}

input TableToDoFilterInput {
    id: TableIDFilterInput
    title: TableStringFilterInput
    completed: Boolean # add here
}

现在它们应该是控制台右上角的橙色按钮“保存架构”。如果您按下它,它将保存您的新架构,并且您可以针对您的 AWS AppSync API 运行一些新查询。

转到查询窗口并将完成添加到您的突变和 listToDos 选择集中。

# Click the orange "Play" button and select the createToDo
# mutation to create an object in DynamoDB.
# If you see an error that starts with "Unable to assume role",
# wait a moment and try again.
mutation createToDo($createtodoinput: CreateToDoInput!) {
  createToDo(input: $createtodoinput) {
    id
    title
    completed
  }
}


# After running createToDo, try running the listToDos query.
query listToDos {
  listToDos {
    items {
      id
      title
      completed
    }
  }
}

更新您的查询变量以包含已完成的值

{
  "createtodoinput": {
    "title": "Hello, world!",
    "completed":true
  }
}

对于一个简单的属性,这应该是您需要做的所有事情。

【讨论】:

  • 感谢您的回答,但这就是为什么我想避免手动进行所有更改,希望在网络上有一个“更新资源”(amplify api gql-compile && amplify push)按钮,可以跟踪突变和查询,我可以只关注架构,因为您的解释适用于简单的更新。
猜你喜欢
  • 2019-07-11
  • 1970-01-01
  • 2020-02-16
  • 2019-08-09
  • 2020-07-24
  • 2019-09-22
  • 2019-06-29
  • 2019-04-15
  • 2019-04-21
相关资源
最近更新 更多