From the course: Learning AWS Amplify

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Fetch items from the server

Fetch items from the server

- [Instructor] Fetching items from the database is actually pretty easy, and you can specify some predicates as far as what values you want to search for. So I'm going to write a new function in my project on line 27 called listPicos, and it's also going to be an async function. And the first thing I'm going to do is I'm going to get the keys. This is off of Pico.keys. This is the coding keys from the enumeration on Pico. So I can specify any of these values in the predicate as far as what I want to match. So I'm going to make the predicate be keys.username equal equal beartest. So I should be able to fetch all of the items in the database for that user. Then I'm going to create the request. And I'm going to set that equal to the GraphQL Request. And I'm going to specify the generic to be Pico. And then I'm going to use list to specify what I want to fetch. I want to fetch the Pico type, so I'll do Pico.self. And then I…

Contents