Skip to content

Commit

Permalink
Merge pull request #553 from liteflow-labs/chore/flatten-FetchCollect…
Browse files Browse the repository at this point in the history
…ionTraits-query

Flatten `FetchCollectionTraits` query
  • Loading branch information
NicolasMahe authored Feb 1, 2024
2 parents d698be9 + 4d4144c commit f862163
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
24 changes: 9 additions & 15 deletions components/Filter/FilterBy/Trait.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const FilterByTrait: FC<Props> = ({
notifyOnNetworkStatusChange: true,
})

const traitsData = data?.collection?.traitsOfCollection.nodes
const hasNextPage = data?.collection?.traitsOfCollection.pageInfo.hasNextPage
const traitsData = data?.collectionTraits?.nodes
const hasNextPage = data?.collectionTraits?.pageInfo.hasNextPage

const loadMore = useCallback(async () => {
const newOffset = offset + PAGINATION_LIMIT
Expand All @@ -76,22 +76,16 @@ const FilterByTrait: FC<Props> = ({
// Cannot use concatToQuery function because of nested cache
// Nested cache comes from the shape of FetchCollectionTraits query above
updateQuery: (prevResult, { fetchMoreResult }) => {
if (
!fetchMoreResult ||
!fetchMoreResult.collection?.traitsOfCollection
)
if (!fetchMoreResult || !fetchMoreResult.collectionTraits)
return prevResult
return {
...fetchMoreResult,
collection: {
...fetchMoreResult.collection,
traitsOfCollection: {
...fetchMoreResult.collection.traitsOfCollection,
nodes: [
...(prevResult?.collection?.traitsOfCollection.nodes || []),
...fetchMoreResult.collection.traitsOfCollection.nodes,
],
},
collectionTraits: {
...fetchMoreResult.collectionTraits,
nodes: [
...(prevResult?.collectionTraits?.nodes || []),
...fetchMoreResult.collectionTraits.nodes,
],
},
}
},
Expand Down
48 changes: 24 additions & 24 deletions hooks/useFetchCollectionTraits.gql
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
query FetchCollectionTraits(
$chainId: Int!
$address: Address!
$filter: CollectionTraitFilter!
$filter: [CollectionTraitFilter!]
$limit: Int!
$offset: Int!
) {
collection(chainId: $chainId, address: $address) {
chainId
address
traitsOfCollection(
orderBy: [TYPE_ASC]
first: $limit
filter: $filter
offset: $offset
) {
pageInfo {
hasNextPage
}
nodes {
type
numberOfValues
values(
first: 50 # TODO: implement pagination
orderBy: [NUMBER_OF_ASSETS_DESC, VALUE_ASC]
) {
nodes {
value
numberOfAssets
}
collectionTraits(
orderBy: [TYPE_ASC]
first: $limit
filter: {
chainId: { equalTo: $chainId }
collectionAddress: { equalTo: $address }
and: $filter
}
offset: $offset
) {
pageInfo {
hasNextPage
}
nodes {
type
numberOfValues
values(
first: 50 # TODO: implement pagination
orderBy: [NUMBER_OF_ASSETS_DESC, VALUE_ASC]
) {
nodes {
value
numberOfAssets
}
}
}
Expand Down

0 comments on commit f862163

Please sign in to comment.