Skip to content

Commit

Permalink
Merge pull request #1004 from artsy/empty_rva
Browse files Browse the repository at this point in the history
@mzikherman => Make sure to return an empty connection when RVA is empty
  • Loading branch information
mzikherman authored Apr 12, 2018
2 parents d09ceb2 + d3b070c commit fb1f280
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/schema/me/__tests__/recently_viewed_artworks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ describe("RecentlyViewedArtworks", () => {
)
})

it("can return an empty connection", () => {
const query = gql`
{
me {
recentlyViewedArtworks(first: 1) {
edges {
node {
id
title
}
}
pageInfo {
hasNextPage
}
}
}
}
`
rootValue.meLoader = () =>
Promise.resolve({ recently_viewed_artwork_ids: [] })
expect.assertions(1)
return runAuthenticatedQuery(query, rootValue).then(
({ me: { recentlyViewedArtworks } }) => {
expect(recentlyViewedArtworks).toEqual({
edges: [],
pageInfo: {
hasNextPage: false,
},
})
}
)
})

it("records an artwork view", () => {
const mutation = gql`
mutation {
Expand Down
4 changes: 4 additions & 0 deletions src/schema/me/recently_viewed_artworks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from "graphql"
import {
connectionFromArray,
connectionFromArraySlice,
mutationWithClientMutationId,
} from "graphql-relay"
Expand All @@ -17,6 +18,9 @@ export const RecentlyViewedArtworks = {
_request,
{ rootValue: { artworksLoader } }
) => {
if (ids.length === 0) {
return connectionFromArray(ids, options)
}
const { offset } = getPagingParameters(options)
return artworksLoader({ ids }).then(body => {
return connectionFromArraySlice(body, options, {
Expand Down

0 comments on commit fb1f280

Please sign in to comment.