How Relationships and resolving data work
masterMangaDex returns Relationship objects for associated data (like authors or artists) instead of the full object to save bandwidth. To access the actual data, you must use the .resolve() method on the relationship.
Optimization via includes
You can pass an array of strings to the includes parameter in query methods (e.g., Manga.getByQuery({ includes: ['author'] })). This instructs the API to return the associated data immediately. When using includes, the relationship is cached, and calling .resolve() will return the data instantly without a new network request. You can check if a relationship is cached using the .cached property.
Resolving multiple relationships
Use resolveArray() to resolve an array of Relationship objects more efficiently than calling .resolve() on each item individually.
const manga = await Manga.getRandom();
// Resolve a single relationship
const firstAuthor = await manga.authors[0].resolve();
console.log('The first author is', firstAuthor.name);
// Resolve an array of relationships efficiently
const allAuthors = await resolveArray(manga.authors);
console.log('All authors are', allAuthors.map((a) => a.name).join(', '));
// Using 'includes' to cache data
const otherManga = await Manga.getByQuery({ includes: ['author'] });
if (otherManga) {
console.log('The authors for this manga are included and cached:', otherManga.authors[0].cached);
const author = await otherManga.authors[0].resolve();
console.log('The author is', author.name);
}