From 03cde98eae7aa02678b07e13f557705e49af1ada Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Sun, 31 May 2020 16:08:17 -0700 Subject: [PATCH] fix bug querying depth on restricted zones --- src/server/index.js | 11 +++++++++-- src/server/loaders.js | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index 4525414..f4e440a 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -272,8 +272,15 @@ const resolvers = { }, }, Zone: { - label: async (zone, _, { zoneTranslationLoader }) => { - const zoneTranslation = await zoneTranslationLoader.load(zone.id); + depth: async ({ id }, _, { zoneLoader }) => { + // 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; }, }, diff --git a/src/server/loaders.js b/src/server/loaders.js index cb8832f..b452bf5 100644 --- a/src/server/loaders.js +++ b/src/server/loaders.js @@ -256,7 +256,8 @@ const buildZoneLoader = (db) => return ids.map( (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( (zoneId) => - entitiesByZoneId.get(zoneId) || + entitiesByZoneId.get(String(zoneId)) || new Error(`could not find translation for zone ${zoneId}`) ); });