AWS AppSync更新架构 [英] AWS AppSync Update Schema

查看:102
本文介绍了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 Web控制台做到这一点?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆