Oops, fix item previews with bodyId=0!

The other day, I deleted what was apparently a load-bearing glitch row, lol 😂

We had a row in pet_types that somehow had `body_id = 0`. And I guess that was causing this query to return some species, even though that body has no species.

Here, I'm adding support for the special `representsAllBodies` body's species to be null. The client seems chill with it, we weren't using that property in that situation anyway!
This commit is contained in:
Emi Matchu 2021-03-15 08:22:11 -07:00
parent c0e70b4c62
commit 1dce12e792
2 changed files with 15 additions and 7 deletions

View file

@ -457,12 +457,15 @@ const resolvers = {
GROUP BY swf_assets.body_id GROUP BY swf_assets.body_id
-- We have some invalid data where the asset has a body ID that -- We have some invalid data where the asset has a body ID that
-- matches no pet type. Huh! Well, ignore those bodies! -- matches no pet type. Huh! Well, ignore those bodies!
HAVING speciesId IS NOT NULL; HAVING speciesId IS NOT NULL OR bodyId = 0;
`, `,
[id] [id]
); );
return rows.map((row) => ({ return rows.map((row) => ({
body: { id: row.bodyId, species: { id: row.speciesId } }, body: {
id: row.bodyId,
species: row.speciesId ? { id: row.speciesId } : null,
},
zones: row.zoneIds.split(",").map((zoneId) => ({ id: zoneId })), zones: row.zoneIds.split(",").map((zoneId) => ({ id: zoneId })),
})); }));
}, },

View file

@ -49,14 +49,16 @@ const typeDefs = gql`
type Body @cacheControl(maxAge: ${oneDay}, staleWhileRevalidate: ${oneWeek}) { type Body @cacheControl(maxAge: ${oneDay}, staleWhileRevalidate: ${oneWeek}) {
id: ID! id: ID!
species: Species!
# Whether this is the special body type that represents fitting _all_ pets.
representsAllBodies: Boolean!
# The species this body belongs to. Null if representsAllBodies is true.
species: Species
# A PetAppearance that has this body. Prefers Blue (or the optional # A PetAppearance that has this body. Prefers Blue (or the optional
# preferredColorId), and happy poses. # preferredColorId), and happy poses.
canonicalAppearance(preferredColorId: ID): PetAppearance canonicalAppearance(preferredColorId: ID): PetAppearance
# Whether this is the special body type that represents fitting _all_ pets.
representsAllBodies: Boolean!
} }
type PetAppearance @cacheControl(maxAge: ${oneHour}, staleWhileRevalidate: ${oneWeek}) { type PetAppearance @cacheControl(maxAge: ${oneHour}, staleWhileRevalidate: ${oneWeek}) {
@ -188,7 +190,10 @@ const resolvers = {
}, },
Body: { Body: {
species: ({ species }) => { species: ({ id, species }) => {
if (id == "0") {
return null;
}
if (species) { if (species) {
return species; return species;
} }