fix apollo client 3 initial item load bug

I guess if you return a reference to an object that doesn't exist, it registers as null; and you need to provide the `true` here to declare that it _is_ real and should be treated as an _insufficiently_ defined object?
This commit is contained in:
Emi Matchu 2020-07-31 23:21:09 -07:00
parent 8211444d67
commit 7f8401ff4b
2 changed files with 7 additions and 4 deletions

View file

@ -62,7 +62,7 @@ function useOutfitState() {
}
);
const items = (data && data.items) || [];
const items = data?.items || [];
const itemsById = {};
for (const item of items) {
itemsById[item.id] = item;

View file

@ -8,8 +8,11 @@ const typePolicies = {
// when you remove an item from your outfit, or add an item from search,
// Apollo knows it already has the data it needs and doesn't need to ask
// the server again!
items: (_, { args, toReference }) =>
args.ids.map((id) => toReference({ __typename: "Item", id })),
items: (_, { args, toReference }) => {
return args.ids.map((id) =>
toReference({ __typename: "Item", id }, true)
);
},
// Teach Apollo how to serve `petAppearance` queries from the cache. That
// way, when you switch pet poses, Apollo knows it already has the
@ -17,7 +20,7 @@ const typePolicies = {
petAppearance: (_, { args, toReference }) => {
const { speciesId, colorId, pose } = args;
const id = `${speciesId}-${colorId}-${pose}`;
return toReference({ __typename: "PetAppearance", id });
return toReference({ __typename: "PetAppearance", id }, true);
},
},
},