Like creating the original schema, updating the schema can be done through a variety of means. You can select another DynamoDB table to add to the schema. This modifies the original schema which can then have code generated and overwrite the previous version. Or you can define new types and have AppSync update the schema.
- [Instructor] So now we want to be able to, add posts to all of our data on the server. We can't store em in the same table as the settings, that just wouldn't be efficient, it would be the wrong columns and get data mixed up. There's a lot of reasons not to do that. So we need a new data source there. So let's look at our API in AppSync. So here we are in AppSync, and we've got our schema, we've got our data sources. We could create a new data source, and we could name it something like post, and we can specify it as a DynamoDB table, and it's going to ask the region, and then it's going to ask the table name.
We don't have one. If we already had a table this could be a great way to go, this might be what you need to do, if you have an existing table you want to add to your API. But we don't. So where going to go back to schema, and we're going to say create resources. We're going to define a new resource for our post. So we'll name the type post, and we're going to have it have an ID, that's good. And then after that we're going to have some other data, we'll have the use ID which is a string, we'll have the username which is a string, we'll have the thought itself, which is the text of the thought or note.
Let's see, what else do we have in the code? So if we go to our thoughts table view controller class, up at the top we've got our post class, name, thought, latitude and longitude, and a created at which is a number. So these are all numbers. So we'll come back here and we'll say, lat is a float, longitude is a float. And created at is also a float. And if we scroll down here we can see, it's going to create post table with a primary key of the ID.
That's good. The sort key we'll set as the user ID, so those will be all sorted together. And this switch for automatically generate the graph QL, we want that to be on. So we have all of our schema generated for us in graph QL, and all we have to do is click create. So it's creating the database table. So we can go over to DynamoDB. And if we refresh this, we'll see the table's getting created.
And it's creating the data sources, the resolvers, it's doing all the work for us. And then it's done. So now we have to be able to update our local version, with all of that information as well. Well as we saw before we can just use amplify code gen. And we'll do that in the next video.
- Preparing to use AppSync in code
- Updating settings and the schema
- Adding a second data source
- Storing posts online
- Updating subscriptions in schema
- Testing live updates
- Handling updated posts
- Offline capabilities