Load relations sequentially (#212)

This commit is contained in:
nikugogoi 2022-11-03 14:32:34 +05:30 committed by GitHub
parent 2517f110ea
commit be65ca45ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -632,8 +632,9 @@ export class Database {
return entities;
}
const relationPromises = selections.filter((selection) => selection.kind === 'Field' && Boolean(relations[selection.name.value]))
.map(async selection => {
const relationSelections = selections.filter((selection) => selection.kind === 'Field' && Boolean(relations[selection.name.value]));
for (const selection of relationSelections) {
assert(selection.kind === 'Field');
const field = selection.name.value;
const { entity: relationEntity, isArray, isDerived, field: foreignKey } = relations[field];
@ -684,7 +685,7 @@ export class Database {
}
});
return;
continue;
}
if (isArray) {
@ -728,7 +729,7 @@ export class Database {
});
});
return;
continue;
}
// field is neither an array nor derivedFrom
@ -738,7 +739,7 @@ export class Database {
entity[field] = { id: entity[field] };
});
return;
continue;
}
const where: Where = {
@ -770,9 +771,7 @@ export class Database {
entity[field] = relatedEntitiesMap[entity[field]];
}
});
});
await Promise.all(relationPromises);
}
return entities;
}