* Which Category is your question related to? *
DataStore
* What AWS Services are you utilizing? *
AppSync
* Provide additional details e.g. code snippets *
I unexpectedly ran across the documentation for DataStore today and it made me question the future of my app. Is DataStore essentially a replacement for the API module? It seems to do everything it can, and even offline. I have a React app and I really like the idea of not having to use the
As far as I understand DataStore is NOT replacement for API module. They both have future individually. As you can tell Datastore is specialized for offline use case.
DataStore is a new way of building applications with a local-first mental model. We are not looking at deprecating the API category, and in some ways you could look at DataStore as a higher level construct of multiple categories (API, Storage, etc.) where you use the others in conjunction with DataStore if you need more control.
I would recommend trying to use DataStore first and seeing if it meets your needs. Being a new paradigm there are still a few pieces of functionality and feature request we are working to deliver, so having customer feedback helps prioritization.
@undefobj @apoorvmote How does DataStore work with @key's? Suppose I had a user graphql model and I wanted to query for a user with a certain email. If I went with the DataStore approach, would I need to specify an @key(name: "userByEmail", fields: ["email"], queryField: "userByEmail") ? Based on the documentation it doesn't look like there is an opportunity to tell DataStore how to query the api, but you instead just tell it what you want. What is going on behind the scenes in the aforementioned query?
I would of course like to take advantage of the performance boost by using gsi's, but I'm curious as to how DataStore performs on a query like:
DataStore.query(User, u => u.email("eq", "myemail"))
Datastore will sync/download all available users for offline use. So you can query datasource with any user parameter while offline. So you won't need custom GSI key at all when querying with datastore.
If you don't want to sync/download all available users for offline use then either restrict them by auth e.g. @auth(rules: [{allow: owner}]) or don't use datastore and query with API module using gsi only while online.
DataStore can use @key with relations: https://aws-amplify.github.io/docs/js/datastore#relational-models
@undefobj Yes documentation says you can use @key but in testing it failed. I have made bug report #5088
Thanks @apoorvmote we're going to do a deeper investigation into this as well as some enhancements to @key functionality in the upcoming sprints. I've noted this as one of the issues to look at.