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

Flatten FetchCollectionTraits query #553

Merged
merged 1 commit into from
Feb 1, 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
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
Loading