Skip to content

Commit

Permalink
feat(FX-4725): allow counting only visible artworks for collections (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nickskalkin committed Apr 11, 2023
1 parent 631ea38 commit b1436ab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
5 changes: 4 additions & 1 deletion _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,10 @@ type Collection {
): ArtworkConnection

# Number of artworks associated with this collection.
artworksCount: Int!
artworksCount(
# Only count visible artworks
onlyVisible: Boolean = false
): Int!

# True if this is the default collection for this user, i.e. the default Saved Artwork collection.
default: Boolean!
Expand Down
50 changes: 50 additions & 0 deletions src/schema/v2/me/__tests__/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const mockGravityCollection = {
default: false,
saves: true,
artworks_count: 42,
visible_artworks_count: 39,
}

let context: Partial<ResolverContext>
Expand Down Expand Up @@ -135,6 +136,55 @@ describe("isSavedArtwork field", () => {
})
})

describe("artworksCount field", () => {
it("should return visible_artworks_count if onlyVisible is true", async () => {
const countQuery = gql`
query {
me {
collection(id: "123-abc") {
artworksCount(onlyVisible: true)
}
}
}
`
const response = await runAuthenticatedQuery(countQuery, context)

expect(response.me.collection.artworksCount).toBe(
mockGravityCollection.visible_artworks_count
)
})

it("should return artworks_count if onlyVisible is false or not passed", async () => {
let countQuery = gql`
query {
me {
collection(id: "123-abc") {
artworksCount(onlyVisible: false)
}
}
}
`
let response = await runAuthenticatedQuery(countQuery, context)
expect(response.me.collection.artworksCount).toBe(
mockGravityCollection.artworks_count
)

countQuery = gql`
query {
me {
collection(id: "123-abc") {
artworksCount
}
}
}
`
response = await runAuthenticatedQuery(countQuery, context)
expect(response.me.collection.artworksCount).toBe(
mockGravityCollection.artworks_count
)
})
})

describe("artworksConnection", () => {
const mockGravityCollectionArtworks = {
headers: {
Expand Down
14 changes: 13 additions & 1 deletion src/schema/v2/me/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ export const CollectionType = new GraphQLObjectType<any, ResolverContext>({
artworksCount: {
type: new GraphQLNonNull(GraphQLInt),
description: "Number of artworks associated with this collection.",
resolve: ({ artworks_count }) => artworks_count,
args: {
onlyVisible: {
type: GraphQLBoolean,
description: "Only count visible artworks",
defaultValue: false,
},
},
resolve: (
{ artworks_count, visible_artworks_count },
{ onlyVisible }
) => {
return onlyVisible ? visible_artworks_count : artworks_count
},
},
default: {
type: new GraphQLNonNull(GraphQLBoolean),
Expand Down

0 comments on commit b1436ab

Please sign in to comment.