omit glitched pet states, add IDs
This commit is contained in:
parent
da82dba294
commit
d9b447bbb4
4 changed files with 37 additions and 10 deletions
|
@ -47,8 +47,10 @@ const typeDefs = gql`
|
|||
}
|
||||
|
||||
type PetAppearance {
|
||||
id: ID!
|
||||
genderPresentation: GenderPresentation
|
||||
emotion: Emotion
|
||||
approximateThumbnailUrl: String!
|
||||
layers: [AppearanceLayer!]!
|
||||
}
|
||||
|
||||
|
@ -159,6 +161,7 @@ const resolvers = {
|
|||
},
|
||||
},
|
||||
PetAppearance: {
|
||||
id: ({ petState }) => petState.id,
|
||||
genderPresentation: ({ petState }) => {
|
||||
if (petState.female === 1) {
|
||||
return "FEMININE";
|
||||
|
@ -187,6 +190,9 @@ const resolvers = {
|
|||
);
|
||||
}
|
||||
},
|
||||
approximateThumbnailUrl: ({ petType, petState }) => {
|
||||
return `http://pets.neopets.com/cp/${petType.basicImageHash}/${petState.moodId}/1.png`;
|
||||
},
|
||||
layers: async ({ petState }, _, { petSwfAssetLoader }) => {
|
||||
const swfAssets = await petSwfAssetLoader.load(petState.id);
|
||||
return swfAssets;
|
||||
|
@ -280,26 +286,26 @@ const resolvers = {
|
|||
petAppearance: async (
|
||||
_,
|
||||
{ speciesId, colorId },
|
||||
{ petTypeLoader, petStateLoader, petSwfAssetLoader }
|
||||
{ petTypeLoader, petStateLoader }
|
||||
) => {
|
||||
const petType = await petTypeLoader.load({
|
||||
speciesId,
|
||||
colorId,
|
||||
});
|
||||
const petStates = await petStateLoader.load(petType.id);
|
||||
return { petState: petStates[0] };
|
||||
return { petType, petState: petStates[0] };
|
||||
},
|
||||
petAppearances: async (
|
||||
_,
|
||||
{ speciesId, colorId },
|
||||
{ petTypeLoader, petStateLoader, petSwfAssetLoader }
|
||||
{ petTypeLoader, petStateLoader }
|
||||
) => {
|
||||
const petType = await petTypeLoader.load({
|
||||
speciesId,
|
||||
colorId,
|
||||
});
|
||||
const petStates = await petStateLoader.load(petType.id);
|
||||
return petStates.map((petState) => ({ petState }));
|
||||
return petStates.map((petState) => ({ petType, petState }));
|
||||
},
|
||||
petOnNeopetsDotCom: async (_, { petName }) => {
|
||||
const petData = await neopets.loadPetData(petName);
|
||||
|
|
|
@ -229,8 +229,9 @@ const buildPetStateLoader = (db) =>
|
|||
new DataLoader(async (petTypeIds) => {
|
||||
const qs = petTypeIds.map((_) => "?").join(",");
|
||||
const [rows, _] = await db.execute(
|
||||
`SELECT * FROM pet_states WHERE pet_type_id IN (${qs})
|
||||
ORDER BY glitched ASC, (mood_id = 1) DESC`,
|
||||
`SELECT * FROM pet_states
|
||||
WHERE pet_type_id IN (${qs}) AND glitched = 0
|
||||
ORDER BY (mood_id = 1) DESC`,
|
||||
petTypeIds
|
||||
);
|
||||
|
||||
|
|
|
@ -31,8 +31,9 @@ describe("PetAppearance", () => {
|
|||
],
|
||||
],
|
||||
Array [
|
||||
"SELECT * FROM pet_states WHERE pet_type_id IN (?)
|
||||
ORDER BY glitched ASC, (mood_id = 1) DESC",
|
||||
"SELECT * FROM pet_states
|
||||
WHERE pet_type_id IN (?) AND glitched = 0
|
||||
ORDER BY (mood_id = 1) DESC",
|
||||
Array [
|
||||
"2",
|
||||
],
|
||||
|
@ -67,8 +68,10 @@ describe("PetAppearance", () => {
|
|||
query: gql`
|
||||
query {
|
||||
petAppearances(speciesId: "54", colorId: "75") {
|
||||
id
|
||||
genderPresentation
|
||||
emotion
|
||||
approximateThumbnailUrl
|
||||
layers {
|
||||
id
|
||||
imageUrl(size: SIZE_600)
|
||||
|
@ -93,8 +96,9 @@ describe("PetAppearance", () => {
|
|||
],
|
||||
],
|
||||
Array [
|
||||
"SELECT * FROM pet_states WHERE pet_type_id IN (?)
|
||||
ORDER BY glitched ASC, (mood_id = 1) DESC",
|
||||
"SELECT * FROM pet_states
|
||||
WHERE pet_type_id IN (?) AND glitched = 0
|
||||
ORDER BY (mood_id = 1) DESC",
|
||||
Array [
|
||||
"2",
|
||||
],
|
||||
|
|
|
@ -55,8 +55,10 @@ exports[`PetAppearance loads multiple for species and color 1`] = `
|
|||
Object {
|
||||
"petAppearances": Array [
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/1/1.png",
|
||||
"emotion": "HAPPY",
|
||||
"genderPresentation": "FEMININE",
|
||||
"id": "17723",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -103,8 +105,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/1/1.png",
|
||||
"emotion": "HAPPY",
|
||||
"genderPresentation": "MASCULINE",
|
||||
"id": "17742",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -151,8 +155,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/4/1.png",
|
||||
"emotion": "SICK",
|
||||
"genderPresentation": "FEMININE",
|
||||
"id": "10014",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -199,8 +205,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/4/1.png",
|
||||
"emotion": "SICK",
|
||||
"genderPresentation": "MASCULINE",
|
||||
"id": "11089",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -247,8 +255,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/2/1.png",
|
||||
"emotion": "SAD",
|
||||
"genderPresentation": "FEMININE",
|
||||
"id": "5991",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -295,8 +305,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/2/1.png",
|
||||
"emotion": "SAD",
|
||||
"genderPresentation": "MASCULINE",
|
||||
"id": "436",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -343,8 +355,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/null/1.png",
|
||||
"emotion": null,
|
||||
"genderPresentation": null,
|
||||
"id": "2",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
@ -398,8 +412,10 @@ Object {
|
|||
],
|
||||
},
|
||||
Object {
|
||||
"approximateThumbnailUrl": "http://pets.neopets.com/cp/vghhzlgf/null/1.png",
|
||||
"emotion": null,
|
||||
"genderPresentation": null,
|
||||
"id": "4751",
|
||||
"layers": Array [
|
||||
Object {
|
||||
"id": "5995",
|
||||
|
|
Loading…
Reference in a new issue