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!
}
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
}
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.
Is there a way to do this from the AWS AppSync web console?
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
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With