Better support for colorId=0
This is a glitchy state that pets can get into! `spankaroonie` is an example, at time of writing. Before, we would crash on loading downstream fields for the pet's color. Now, we don't! We also fix an oversight in the pet's `petAppearance` field, to trigger the "not yet modeled" error when the pet type doesn't exist.
This commit is contained in:
parent
ddd224c8d1
commit
9e2f9eab16
2 changed files with 17 additions and 3 deletions
|
@ -26,9 +26,11 @@ const typeDefs = gql`
|
|||
const resolvers = {
|
||||
Pet: {
|
||||
species: ({ customPetData }) => ({
|
||||
id: customPetData.custom_pet.species_id,
|
||||
id: String(customPetData.custom_pet.species_id),
|
||||
}),
|
||||
color: ({ customPetData }) => ({
|
||||
id: String(customPetData.custom_pet.color_id),
|
||||
}),
|
||||
color: ({ customPetData }) => ({ id: customPetData.custom_pet.color_id }),
|
||||
pose: ({ customPetData, petMetaData }) =>
|
||||
getPoseFromPetData(petMetaData, customPetData),
|
||||
petAppearance: async (
|
||||
|
@ -40,7 +42,9 @@ const resolvers = {
|
|||
speciesId: customPetData.custom_pet.species_id,
|
||||
colorId: customPetData.custom_pet.color_id,
|
||||
});
|
||||
const petStates = await petStatesForPetTypeLoader.load(petType.id);
|
||||
const petStates = petType
|
||||
? await petStatesForPetTypeLoader.load(petType.id)
|
||||
: [];
|
||||
|
||||
let petState;
|
||||
|
||||
|
|
|
@ -121,10 +121,20 @@ const typeDefs = gql`
|
|||
const resolvers = {
|
||||
Color: {
|
||||
name: async ({ id }, _, { colorTranslationLoader }) => {
|
||||
// TODO: Add colorId=0 to the database? Pets on Neopets.com can have it.
|
||||
if (id === "0") {
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
const colorTranslation = await colorTranslationLoader.load(id);
|
||||
return capitalize(colorTranslation.name);
|
||||
},
|
||||
isStandard: async ({ id }, _, { colorLoader }) => {
|
||||
// TODO: Add colorId=0 to the database? Pets on Neopets.com can have it.
|
||||
if (id === "0") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const color = await colorLoader.load(id);
|
||||
return color.standard ? true : false;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue