Skip to content

Commit edb0489

Browse files
committed
feat: add (record|remove)ArtworkView mutations
- add recordArtworkView mutation to replace stitched version from Gravity - new removeArtworkView mutation
1 parent 2e26ba8 commit edb0489

File tree

8 files changed

+185
-14
lines changed

8 files changed

+185
-14
lines changed

_schemaV2.graphql

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14057,10 +14057,16 @@ type Mutation {
1405714057
input: MyCollectionUpdateArtworkInput!
1405814058
): MyCollectionUpdateArtworkPayload
1405914059
publishViewingRoom(input: PublishViewingRoomInput!): PublishViewingRoomPayload
14060+
14061+
# Record an artwork view.
1406014062
recordArtworkView(
14061-
# Parameters for RecordArtworkView
14062-
input: RecordArtworkViewInput!
14063-
): RecordArtworkViewPayload
14063+
input: RecordArtworkViewMutationInput!
14064+
): RecordArtworkViewMutationPayload
14065+
14066+
# Remove an artwork view.
14067+
removeArtworkView(
14068+
input: RemoveArtworkViewMutationInput!
14069+
): RemoveArtworkViewMutationPayload
1406414070
removeAssetFromConsignmentSubmission(
1406514071
# Parameters for RemoveAssetFromConsignmentSubmission
1406614072
input: RemoveAssetFromConsignmentSubmissionInput!
@@ -17717,23 +17723,18 @@ type RecentlySoldArtworkTypeEdge {
1771717723
node: RecentlySoldArtworkType
1771817724
}
1771917725

17720-
# Autogenerated input type of RecordArtworkView
17721-
input RecordArtworkViewInput {
17726+
input RecordArtworkViewMutationInput {
17727+
# ID of artwork.
1772217728
artwork_id: String!
17723-
17724-
# A unique identifier for the client performing the mutation.
1772517729
clientMutationId: String
1772617730
}
1772717731

17728-
# Autogenerated return type of RecordArtworkView
17729-
type RecordArtworkViewPayload {
17730-
# Id of viewed artwork
17732+
type RecordArtworkViewMutationPayload {
17733+
# ID of viewed artwork.
1773117734
artworkId: String!
1773217735

17733-
# Id of viewed artwork
17734-
artwork_id: String! @deprecated(reason: "Use artworkId")
17735-
17736-
# A unique identifier for the client performing the mutation.
17736+
# ID of viewed artwork.
17737+
artwork_id: String! @deprecated(reason: "Use artworkId.")
1773717738
clientMutationId: String
1773817739
}
1773917740

@@ -17761,6 +17762,21 @@ type RelatedArtworkGrid implements ArtworkContextGrid {
1776117762
title: String
1776217763
}
1776317764

17765+
input RemoveArtworkViewMutationInput {
17766+
# ID of artwork.
17767+
artwork_id: String!
17768+
clientMutationId: String
17769+
}
17770+
17771+
type RemoveArtworkViewMutationPayload {
17772+
# ID of viewed artwork.
17773+
artworkId: String!
17774+
17775+
# ID of viewed artwork.
17776+
artwork_id: String! @deprecated(reason: "Use artworkId.")
17777+
clientMutationId: String
17778+
}
17779+
1776417780
# Autogenerated input type of RemoveAssetFromConsignmentSubmission
1776517781
input RemoveAssetFromConsignmentSubmissionInput {
1776617782
assetID: String

src/lib/loaders/loaders_with_authentication/gravity.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export default (accessToken, userID, opts) => {
7272
{},
7373
{ method: "POST" }
7474
),
75+
createArtworkViewLoader: gravityLoader(
76+
(artworkID) => `artwork/${artworkID}/view`,
77+
{},
78+
{ method: "POST" }
79+
),
7580
createCommerceOptInEligibleArtworksReportLoader: gravityLoader(
7681
(id) => `partner/${id}/commerce_opt_in_eligible_artworks_report`,
7782
{},
@@ -215,6 +220,11 @@ export default (accessToken, userID, opts) => {
215220
{},
216221
{ method: "DELETE" }
217222
),
223+
deleteArtworkViewLoader: gravityLoader(
224+
(artworkID) => `artwork/${artworkID}/view`,
225+
{},
226+
{ method: "DELETE" }
227+
),
218228
deleteBankAccountLoader: gravityLoader(
219229
(id) => `me/bank_account/${id}`,
220230
{},

src/lib/stitching/gravity/schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const executableGravitySchema = () => {
8787
excludedMutations.push("updateViewingRoomArtworks")
8888
excludedMutations.push("updateViewingRoomSubsections")
8989
}
90+
excludedMutations.push("recordArtworkView")
9091

9192
// Types which come from Gravity that are not (yet) needed in MP.
9293
// In the future, these can be removed from this list as they are needed.
@@ -96,6 +97,8 @@ export const executableGravitySchema = () => {
9697
"LotEvent",
9798
"RefundCommissionExemptionInput",
9899
"RefundCommissionExemptionPayload",
100+
"RecordArtworkViewInput",
101+
"RecordArtworkViewPayload",
99102
]
100103

101104
// Return the new modified schema
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable promise/always-return */
2+
import { runAuthenticatedQuery } from "schema/v2/test/utils"
3+
4+
describe("recording an artwork view", () => {
5+
const query = `
6+
mutation {
7+
recordArtworkView(input: { artwork_id: "artwork-id" }) {
8+
artworkId
9+
}
10+
}
11+
`
12+
13+
const context = {
14+
createArtworkViewLoader: () =>
15+
Promise.resolve({ artwork_id: "artwork-id" }),
16+
}
17+
18+
it("records an artwork view", async () => {
19+
const data = await runAuthenticatedQuery(query, context)
20+
expect(data).toEqual({
21+
recordArtworkView: {
22+
artworkId: "artwork-id",
23+
},
24+
})
25+
})
26+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable promise/always-return */
2+
import { runAuthenticatedQuery } from "schema/v2/test/utils"
3+
4+
describe("removing an artwork view", () => {
5+
const query = `
6+
mutation {
7+
removeArtworkView(input: { artwork_id: "artwork-id" }) {
8+
artworkId
9+
}
10+
}
11+
`
12+
13+
const context = {
14+
deleteArtworkViewLoader: () =>
15+
Promise.resolve({ artwork_id: "artwork-id" }),
16+
}
17+
18+
it("removes an artwork view", async () => {
19+
const data = await runAuthenticatedQuery(query, context)
20+
expect(data).toEqual({
21+
removeArtworkView: {
22+
artworkId: "artwork-id",
23+
},
24+
})
25+
})
26+
})

src/schema/v2/recordArtworkView.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { GraphQLNonNull, GraphQLString } from "graphql"
2+
import { mutationWithClientMutationId } from "graphql-relay"
3+
import { ResolverContext } from "types/graphql"
4+
import { GraphQLError } from "graphql"
5+
6+
export interface RecordArtworkViewMutationInput {
7+
artwork_id: string
8+
}
9+
10+
export const recordArtworkViewMutation = mutationWithClientMutationId<
11+
RecordArtworkViewMutationInput,
12+
any,
13+
ResolverContext
14+
>({
15+
name: "RecordArtworkViewMutation",
16+
description: "Record an artwork view.",
17+
inputFields: {
18+
artwork_id: {
19+
type: new GraphQLNonNull(GraphQLString),
20+
description: "ID of artwork.",
21+
},
22+
},
23+
outputFields: {
24+
artwork_id: {
25+
description: "ID of viewed artwork.",
26+
type: new GraphQLNonNull(GraphQLString),
27+
deprecationReason: "Use artworkId.",
28+
},
29+
artworkId: {
30+
description: "ID of viewed artwork.",
31+
type: new GraphQLNonNull(GraphQLString),
32+
},
33+
},
34+
mutateAndGetPayload: async ({ artwork_id }, { createArtworkViewLoader }) => {
35+
try {
36+
const response = await createArtworkViewLoader(artwork_id)
37+
38+
return { artwork_id: response.artwork_id, artworkId: response.artwork_id }
39+
} catch (error) {
40+
throw new GraphQLError(`RecordArtworkViewMutation error: ${error}`)
41+
}
42+
},
43+
})

src/schema/v2/removeArtworkView.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { GraphQLNonNull, GraphQLString } from "graphql"
2+
import { mutationWithClientMutationId } from "graphql-relay"
3+
import { ResolverContext } from "types/graphql"
4+
import { GraphQLError } from "graphql"
5+
6+
export interface RemoveArtworkViewMutationInput {
7+
artwork_id: string
8+
}
9+
10+
export const removeArtworkViewMutation = mutationWithClientMutationId<
11+
RemoveArtworkViewMutationInput,
12+
any,
13+
ResolverContext
14+
>({
15+
name: "RemoveArtworkViewMutation",
16+
description: "Remove an artwork view.",
17+
inputFields: {
18+
artwork_id: {
19+
type: new GraphQLNonNull(GraphQLString),
20+
description: "ID of artwork.",
21+
},
22+
},
23+
outputFields: {
24+
artwork_id: {
25+
description: "ID of viewed artwork.",
26+
type: new GraphQLNonNull(GraphQLString),
27+
deprecationReason: "Use artworkId.",
28+
},
29+
artworkId: {
30+
description: "ID of viewed artwork.",
31+
type: new GraphQLNonNull(GraphQLString),
32+
},
33+
},
34+
mutateAndGetPayload: async ({ artwork_id }, { deleteArtworkViewLoader }) => {
35+
try {
36+
const response = await deleteArtworkViewLoader(artwork_id)
37+
38+
return { artworkId: response.artwork_id }
39+
} catch (error) {
40+
throw new GraphQLError(`RemoveArtworkViewMutation error: ${error}`)
41+
}
42+
},
43+
})

src/schema/v2/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ import { unpublishViewingRoomMutation } from "./viewingRooms/mutations/unpublish
268268
import { updateViewingRoomArtworksMutation } from "./viewingRooms/mutations/updateViewingRoomArtworks"
269269
import { updateViewingRoomSubsectionsMutation } from "./viewingRooms/mutations/updateViewingRoomSubsections"
270270
import { ViewingRoomConnection } from "./viewingRooms"
271+
import { recordArtworkViewMutation } from "./recordArtworkView"
272+
import { removeArtworkViewMutation } from "./removeArtworkView"
271273

272274
const viewingRoomUnstitchedRootField = config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
273275
? {
@@ -506,6 +508,8 @@ export default new GraphQLSchema({
506508
myCollectionCreateArtwork: myCollectionCreateArtworkMutation,
507509
myCollectionDeleteArtwork: myCollectionDeleteArtworkMutation,
508510
myCollectionUpdateArtwork: myCollectionUpdateArtworkMutation,
511+
recordArtworkView: recordArtworkViewMutation,
512+
removeArtworkView: removeArtworkViewMutation,
509513
requestCredentialsForAssetUpload: CreateAssetRequestLoader,
510514
requestPriceEstimate: requestPriceEstimateMutation,
511515
saveArtwork: saveArtworkMutation,

0 commit comments

Comments
 (0)