From f6c228b17e9b347510792387535359eb83b659bd Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 19 Aug 2020 18:01:20 -0700 Subject: [PATCH] lol fix cached zone names Ahaha I fucked up a bit! I was indexing into the array of cached zones, instead of looking up by ID. This meant that all zone names were wrong, and some search results weren't loading bc there was no zone data! I made a fix here, and also added some fallback values, so that if there's an issue in the future we can at least fall back more gracefully than the infinite-spinner case we had here. --- src/app/apolloClient.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/apolloClient.js b/src/app/apolloClient.js index 5c102d2..000315e 100644 --- a/src/app/apolloClient.js +++ b/src/app/apolloClient.js @@ -2,6 +2,7 @@ import { ApolloClient, createHttpLink, InMemoryCache } from "@apollo/client"; import { createPersistedQueryLink } from "apollo-link-persisted-queries"; const cachedZones = require("./cached-data/zones.json"); +const cachedZonesById = new Map(cachedZones.map((z) => [z.id, z])); const typePolicies = { Query: { @@ -30,11 +31,13 @@ const typePolicies = { Zone: { fields: { depth: (depth, { readField }) => { - return depth || cachedZones[readField("id")].depth; + const id = readField("id"); + return depth || cachedZonesById.get(id)?.depth || 0; }, label: (label, { readField }) => { - return label || cachedZones[readField("id")].label; + const id = readField("id"); + return label || cachedZonesById.get(id)?.label || `Zone #${id}`; }, }, },