Skip to content

Commit

Permalink
feat: update the query NFTs to work with Subsquid too (#381)
Browse files Browse the repository at this point in the history
* feat: update the query NFTs to work with Subsquid too

* fix: test file
  • Loading branch information
juanmahidalgo authored Aug 8, 2024
1 parent 470fe94 commit caf4b2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/ports/items/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')}]}`
)
}

Expand Down
7 changes: 4 additions & 3 deletions src/ports/nfts/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ export function createNFTComponent<T extends { id: string }>(options: {

function getFragmentFetcher(filters: NFTFilters & { caller?: string }) {
return async (isCount?: boolean) => {
const variables = getQueryVariables(filters, getSortByProp)
const query = getFetchQuery(
filters,
variables,
fragmentName,
getFragment,
getExtraVariables,
getExtraWhere,
isCount,
filters.category === NFTCategory.ENS ? await getBannedNames() : []
)
const variables = getQueryVariables(filters, getSortByProp)

const { nfts: fragments } = await subgraph.query<{
nfts: T[]
}>(query, variables)
Expand Down Expand Up @@ -114,7 +115,7 @@ export function createNFTComponent<T extends { id: string }>(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
Expand Down
24 changes: 12 additions & 12 deletions src/tests/ports/nfts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand All @@ -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))
)
Expand Down Expand Up @@ -304,16 +304,16 @@ 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,
getCollectionsExtraWhere,
false,
bannedNames
)
const variableQuery = getQueryVariables(filters, getCollectionsOrderBy)
const result = await collectionsNFTsMock.fetch(filters)
expect(result).toEqual(
nftFragments.map((f) => fromCollectionsFragment(f))
Expand Down

0 comments on commit caf4b2e

Please sign in to comment.