diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c6a2776..0308aa5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -37,8 +37,8 @@ model MrCrypto { attHeadwear String attEyes String attMoustache String - totalScore Float - ranking Int + rarityScore Float + rarityRanking Int Transfers Transfer[] E7LTokensLinked E7LToken[] diff --git a/schema.graphql b/schema.graphql index e29fd08..bf6062f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,3 +1,8 @@ +enum AscendDescentByEnum { + asc + desc +} + enum Background { Blue Brown @@ -160,7 +165,7 @@ enum Headwear { type Holder { address: String! - mrCryptosOwned: [MrCrypto!]! + mrCryptosOwned(first: Int! = 100, order: MrCryptoOrderBy! = {by: tokenId, type: desc}, skip: Int! = 0): [MrCrypto!]! numberOfMrCryptos: Int! } @@ -192,8 +197,8 @@ type MrCrypto { imageURL: String! metadata: String! moustache: String! - ranking: Int! - score: Float! + rarityRanking: Int! + rarityScore: Float! tokenId: Int! type: String! } @@ -207,7 +212,18 @@ input MrCryptoFilter { type: Type } +input MrCryptoOrderBy { + by: MrCryptoOrderByEnum! = tokenId + type: AscendDescentByEnum! = desc +} + +enum MrCryptoOrderByEnum { + rarityRanking + tokenId +} + type Mutation { + addE7lCollection(contractAddress: String!, deployedBlock: Int!, imageURL: String!, name: String!): E7L! startIndexationManually: String! } diff --git a/src/indexer/mrcrypto.ts b/src/indexer/mrcrypto.ts index bdc34c2..fa66a84 100644 --- a/src/indexer/mrcrypto.ts +++ b/src/indexer/mrcrypto.ts @@ -233,8 +233,8 @@ async function updateOrCreateMrCrypto( attMoustache: metadata[tokenId].attributes.Moustache, attType: metadata[tokenId].attributes.Type, metadataURL: `https://apinft.racksmafia.com/api/${tokenId}.json`, - totalScore: metadata[tokenId].total_score, - ranking: metadata[tokenId].ranking, + rarityScore: metadata[tokenId].total_score, + rarityRanking: metadata[tokenId].ranking, lastTransferBlock: block, Owner: { connectOrCreate: { diff --git a/src/schema/holder.ts b/src/schema/holder.ts index 6c030f7..04ffaa1 100644 --- a/src/schema/holder.ts +++ b/src/schema/holder.ts @@ -1,11 +1,45 @@ import { builder } from "@/builder"; import { prisma } from "@/db"; +const AscendDescentEnum = builder.enumType("AscendDescentByEnum", { + values: ["asc", "desc"] as const, +}); + +const MrCryptoOrderByEnum = builder.enumType("MrCryptoOrderByEnum", { + values: ["rarityRanking", "tokenId"] as const, +}); + builder.prismaObject("Holder", { fields: (t) => ({ address: t.exposeString("address"), mrCryptosOwned: t.relation("MrCryptosOwned", { - query: { orderBy: { tokenId: "asc" } }, + args: { + first: t.arg.int({ required: true, defaultValue: 100 }), + skip: t.arg.int({ required: true, defaultValue: 0 }), + order: t.arg({ + required: true, + defaultValue: { type: "desc", by: "tokenId" }, + type: builder.inputType("MrCryptoOrderBy", { + fields: (t) => ({ + type: t.field({ + type: AscendDescentEnum, + required: true, + defaultValue: "desc", + }), + by: t.field({ + type: MrCryptoOrderByEnum, + required: true, + defaultValue: "tokenId", + }), + }), + }), + }), + }, + query: (args) => ({ + orderBy: { [args.order.by]: args.order.type }, + take: args.first, + skip: args.skip, + }), }), numberOfMrCryptos: t.field({ select: { diff --git a/src/schema/mr-crypto.ts b/src/schema/mr-crypto.ts index b1ebbcb..230e44b 100644 --- a/src/schema/mr-crypto.ts +++ b/src/schema/mr-crypto.ts @@ -26,8 +26,8 @@ builder.prismaObject("MrCrypto", { eyes: t.exposeString("attEyes"), headwear: t.exposeString("attHeadwear"), moustache: t.exposeString("attMoustache"), - score: t.exposeFloat("totalScore"), - ranking: t.exposeInt("ranking"), + rarityRanking: t.exposeInt("rarityRanking"), + rarityScore: t.exposeFloat("rarityScore"), type: t.exposeString("attType"), }), });