From 69e7fa8816614025a86959ceeb5af83a24cef288 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Thu, 8 Aug 2024 15:55:32 +0200 Subject: [PATCH 1/2] feat: update the query NFTs to work with Subsquid too --- src/ports/items/utils.ts | 4 ++-- src/ports/nfts/component.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ports/items/utils.ts b/src/ports/items/utils.ts index 27a8d16..de72a8b 100644 --- a/src/ports/items/utils.ts +++ b/src/ports/items/utils.ts @@ -231,9 +231,9 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) { if (contractAddresses && contractAddresses.length > 0) { where.push( - `collection_in: [${contractAddresses + `collection_: { id_in: [${contractAddresses .map((contractAddress) => `"${contractAddress}"`) - .join(',')}]` + .join(',')}]}` ) } diff --git a/src/ports/nfts/component.ts b/src/ports/nfts/component.ts index 3953f03..428b34c 100644 --- a/src/ports/nfts/component.ts +++ b/src/ports/nfts/component.ts @@ -47,8 +47,9 @@ export function createNFTComponent(options: { function getFragmentFetcher(filters: NFTFilters & { caller?: string }) { return async (isCount?: boolean) => { + const variables = getQueryVariables(filters, getSortByProp) const query = getFetchQuery( - filters, + variables, fragmentName, getFragment, getExtraVariables, @@ -56,7 +57,7 @@ export function createNFTComponent(options: { isCount, filters.category === NFTCategory.ENS ? await getBannedNames() : [] ) - const variables = getQueryVariables(filters, getSortByProp) + const { nfts: fragments } = await subgraph.query<{ nfts: T[] }>(query, variables) @@ -114,7 +115,7 @@ export function createNFTComponent(options: { getMarketplaceSubgraphNameChain(getMarketplaceChainId()) ) ) - const ids = await client.query<{ id: string }>( + const ids = await client.query<{ id: string; subdomain: string }>( getFuzzySearchQueryForENS( schemaName.rows[0].entity_schema, options.search From d983f62aea5ec80af0be1f1f9c42aa69601fbfa9 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Thu, 8 Aug 2024 16:08:33 +0200 Subject: [PATCH 2/2] fix: test file --- src/tests/ports/nfts.spec.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tests/ports/nfts.spec.ts b/src/tests/ports/nfts.spec.ts index 8c85db2..82112fd 100644 --- a/src/tests/ports/nfts.spec.ts +++ b/src/tests/ports/nfts.spec.ts @@ -192,17 +192,17 @@ describe('when fetching emotes', () => { }) it('should return the converted fragment of nfts', async () => { - const fetchQuery = getFetchQuery( + const variableQuery = getQueryVariables( filters, + getCollectionsOrderBy + ) + const fetchQuery = getFetchQuery( + variableQuery, collectionsFragment, getCollectionsFragment, getCollectionsExtraVariables, getCollectionsExtraWhere ) - const variableQuery = getQueryVariables( - filters, - getCollectionsOrderBy - ) expect(collectionsNFTsMock.fetch(filters)).resolves.toEqual( nftFragments.map((f) => fromCollectionsFragment(f)) ) @@ -222,17 +222,17 @@ describe('when fetching emotes', () => { }) it('should return the converted fragment of nfts', () => { - const fetchQuery = getFetchQuery( + const variableQuery = getQueryVariables( filters, + getCollectionsOrderBy + ) + const fetchQuery = getFetchQuery( + variableQuery, collectionsFragment, getCollectionsFragment, getCollectionsExtraVariables, getCollectionsExtraWhere ) - const variableQuery = getQueryVariables( - filters, - getCollectionsOrderBy - ) expect(collectionsNFTsMock.fetch(filters)).resolves.toEqual( nftFragments.map((f) => fromCollectionsFragment(f)) ) @@ -304,8 +304,9 @@ describe('when fetching nfts', () => { }) it('should fetch the banned names and filter the query based on them', async () => { + const variableQuery = getQueryVariables(filters, getCollectionsOrderBy) const fetchQuery = getFetchQuery( - filters, + variableQuery, collectionsFragment, getCollectionsFragment, getCollectionsExtraVariables, @@ -313,7 +314,6 @@ describe('when fetching nfts', () => { false, bannedNames ) - const variableQuery = getQueryVariables(filters, getCollectionsOrderBy) const result = await collectionsNFTsMock.fetch(filters) expect(result).toEqual( nftFragments.map((f) => fromCollectionsFragment(f))