Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update the query NFTs to work with Subsquid too #381

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading