AWS Nov 18, 2022

NEW: Lazy loading & nested query predicates for AWS Amplify DataStore

Article Summary

AWS Amplify just shipped three game-changing features that make querying relational data feel less like a chore and more like writing plain JavaScript. If you've ever wrestled with loading nested data in offline-first apps, this one's for you.

AWS announced major enhancements to Amplify DataStore, their offline-capable data sync solution for mobile and web apps. The update focuses on making relational data queries more intuitive with lazy loading, nested predicates, and improved TypeScript support.

Key Takeaways

Critical Insight

Amplify DataStore now handles relational data queries with native JavaScript patterns, eliminating the awkward syntax that previously made nested queries painful.

The article includes a working demo app that shows how to build an export feature and smart filtering using just a few lines of the new syntax.

About This Article

Problem

Developers building offline-first apps with AWS Amplify DataStore had trouble iterating through related data across multiple relationship types like hasOne, hasMany, belongsTo, and manyToMany. The lack of native async/await support made this work tedious.

Solution

AWS added JavaScript's built-in async iterator support and a `toArray()` function. Now developers can use `for await` loops and async/await patterns to traverse nested relationships like comments and replies.

Impact

A new tutorial shows how to build an export feature that takes blog posts with their comments and nested replies, then formats them into downloadable text files. It demonstrates the lazy loading capabilities across three levels of relational data.