update PetAppearance id to match petStateId

Previously, we were using a custom-y `id` field to help Apollo cross-reference `petAppearance` queries with the results from bulk `petAppearances` queries. Now, instead, we deprecate `petStateId`, and start using `id` to have the same stable value!

This is in anticipation of pet appearance support tools: a stable ID will make it easier to edit them, esp changing their pose (which would otherwise have changed the ID!)
This commit is contained in:
Emi Matchu 2020-08-27 21:32:22 -07:00
parent bf21716db0
commit 59ffc86481
2 changed files with 16 additions and 22 deletions

View file

@ -297,7 +297,7 @@ function PoseOption({ poseInfo, onChange, inputRef }) {
? // A lil debug output, so that we can quickly identify glitched ? // A lil debug output, so that we can quickly identify glitched
// PetStates and manually mark them as glitched! // PetStates and manually mark them as glitched!
window.location.hostname.includes("localhost") && window.location.hostname.includes("localhost") &&
`#${poseInfo.petStateId}` `#${poseInfo.id}`
: "Not modeled yet" : "Not modeled yet"
} }
position="relative" position="relative"
@ -422,7 +422,6 @@ function usePoses(speciesId, colorId, selectedPose) {
fragment PetAppearanceForPosePicker on PetAppearance { fragment PetAppearanceForPosePicker on PetAppearance {
id id
petStateId
bodyId bodyId
pose pose
...PetAppearanceForOutfitPreview ...PetAppearanceForOutfitPreview

View file

@ -97,7 +97,7 @@ const typeDefs = gql`
bodyId: ID! bodyId: ID!
layers: [AppearanceLayer!]! layers: [AppearanceLayer!]!
petStateId: ID! # Convenience field for developers petStateId: ID! # Deprecated, an alias for id
} }
type ItemAppearance { type ItemAppearance {
@ -319,35 +319,30 @@ const resolvers = {
}, },
}, },
PetAppearance: { PetAppearance: {
id: async ({ petStateId }, _, { petStateLoader, petTypeLoader }) => { color: async ({ id }, _, { petStateLoader, petTypeLoader }) => {
const petState = await petStateLoader.load(petStateId); const petState = await petStateLoader.load(id);
const petType = await petTypeLoader.load(petState.petTypeId);
const pose = getPoseFromPetState(petState);
return `${petType.speciesId}-${petType.colorId}-${pose}`;
},
color: async ({ petStateId }, _, { petStateLoader, petTypeLoader }) => {
const petState = await petStateLoader.load(petStateId);
const petType = await petTypeLoader.load(petState.petTypeId); const petType = await petTypeLoader.load(petState.petTypeId);
return { id: petType.colorId }; return { id: petType.colorId };
}, },
species: async ({ petStateId }, _, { petStateLoader, petTypeLoader }) => { species: async ({ id }, _, { petStateLoader, petTypeLoader }) => {
const petState = await petStateLoader.load(petStateId); const petState = await petStateLoader.load(id);
const petType = await petTypeLoader.load(petState.petTypeId); const petType = await petTypeLoader.load(petState.petTypeId);
return { id: petType.speciesId }; return { id: petType.speciesId };
}, },
bodyId: async ({ petStateId }, _, { petStateLoader, petTypeLoader }) => { bodyId: async ({ id }, _, { petStateLoader, petTypeLoader }) => {
const petState = await petStateLoader.load(petStateId); const petState = await petStateLoader.load(id);
const petType = await petTypeLoader.load(petState.petTypeId); const petType = await petTypeLoader.load(petState.petTypeId);
return petType.bodyId; return petType.bodyId;
}, },
pose: async ({ petStateId }, _, { petStateLoader }) => { pose: async ({ id }, _, { petStateLoader }) => {
const petState = await petStateLoader.load(petStateId); const petState = await petStateLoader.load(id);
return getPoseFromPetState(petState); return getPoseFromPetState(petState);
}, },
layers: async ({ petStateId }, _, { petSwfAssetLoader }) => { layers: async ({ id }, _, { petSwfAssetLoader }) => {
const swfAssets = await petSwfAssetLoader.load(petStateId); const swfAssets = await petSwfAssetLoader.load(id);
return swfAssets; return swfAssets;
}, },
petStateId: ({ id }) => id,
}, },
AppearanceLayer: { AppearanceLayer: {
bodyId: async ({ id }, _, { swfAssetLoader }) => { bodyId: async ({ id }, _, { swfAssetLoader }) => {
@ -501,7 +496,7 @@ const resolvers = {
}, },
petAppearance: async ({ id }, _, { outfitLoader }) => { petAppearance: async ({ id }, _, { outfitLoader }) => {
const outfit = await outfitLoader.load(id); const outfit = await outfitLoader.load(id);
return { petStateId: outfit.petStateId }; return { id: outfit.petStateId };
}, },
wornItems: async ({ id }, _, { itemOutfitRelationshipsLoader }) => { wornItems: async ({ id }, _, { itemOutfitRelationshipsLoader }) => {
const relationships = await itemOutfitRelationshipsLoader.load(id); const relationships = await itemOutfitRelationshipsLoader.load(id);
@ -576,7 +571,7 @@ const resolvers = {
return null; return null;
} }
return { petStateId: petState.id }; return { id: petState.id };
}, },
petAppearances: async ( petAppearances: async (
_, _,
@ -589,7 +584,7 @@ const resolvers = {
}); });
const petStates = await petStatesForPetTypeLoader.load(petType.id); const petStates = await petStatesForPetTypeLoader.load(petType.id);
petStates.sort((a, b) => a.id - b.id); petStates.sort((a, b) => a.id - b.id);
return petStates.map((petState) => ({ petStateId: petState.id })); return petStates.map((petState) => ({ id: petState.id }));
}, },
outfit: (_, { id }) => ({ id }), outfit: (_, { id }) => ({ id }),
petOnNeopetsDotCom: async (_, { petName }) => { petOnNeopetsDotCom: async (_, { petName }) => {