fix bug querying depth on restricted zones

This commit is contained in:
Matt Dunn-Rankin 2020-05-31 16:08:17 -07:00
parent caefc6610c
commit 03cde98eae
2 changed files with 12 additions and 4 deletions

View file

@ -272,8 +272,15 @@ const resolvers = {
}, },
}, },
Zone: { Zone: {
label: async (zone, _, { zoneTranslationLoader }) => { depth: async ({ id }, _, { zoneLoader }) => {
const zoneTranslation = await zoneTranslationLoader.load(zone.id); // TODO: Should we extend this loader-in-field pattern elsewhere? I like
// that we avoid the fetch in cases where we only want the zone ID,
// but it adds complexity 🤔
const zone = await zoneLoader.load(id);
return zone.depth;
},
label: async ({ id }, _, { zoneTranslationLoader }) => {
const zoneTranslation = await zoneTranslationLoader.load(id);
return zoneTranslation.label; return zoneTranslation.label;
}, },
}, },

View file

@ -256,7 +256,8 @@ const buildZoneLoader = (db) =>
return ids.map( return ids.map(
(id) => (id) =>
entitiesById.get(id) || new Error(`could not find zone with ID: ${id}`) entitiesById.get(String(id)) ||
new Error(`could not find zone with ID: ${id}`)
); );
}); });
@ -273,7 +274,7 @@ const buildZoneTranslationLoader = (db) =>
return zoneIds.map( return zoneIds.map(
(zoneId) => (zoneId) =>
entitiesByZoneId.get(zoneId) || entitiesByZoneId.get(String(zoneId)) ||
new Error(`could not find translation for zone ${zoneId}`) new Error(`could not find translation for zone ${zoneId}`)
); );
}); });