AWS AppSync 更新架构

编程入门 行业动态 更新时间:2024-10-27 18:23:53
本文介绍了AWS AppSync 更新架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using AWS AppSync web console, I created a new API from scratch.

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

I created a new resource like this:

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

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

After AWS AppSync created the DynamoDB table and Schema, what can I do if I want to update the schema and add a new field?

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

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

I know AWS Amplify has a command amplify api gql-compile and then amplify push and it will update the schema and the DynamoDB tables.

是否可以通过 AWS AppSync 网络控制台执行此操作?>

Is there a way to do this from the AWS AppSync web console?

推荐答案

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

If you used the AWS AppSync Console wizard to create this. You will need to do the following:

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
}

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

Now their should be an orange button "Save Schema" in the upper right hand corner of the console. If you press that it will save your new schema and you can run some new queries against your AWS AppSync API.

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

Go to the query window and add completed into your mutation and listToDos selection sets.

# 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
    }
  }
}

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

Update your query variables to include a value for completed

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

对于一个简单的属性,这应该就是您需要做的全部工作.

That should be all you need to do for a simple attribute.

这篇关于AWS AppSync 更新架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 01:48:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/674936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   AWS   AppSync

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!