Skip to content

Commit 2e26ba8

Browse files
authored
fix: bring back unstitched viewingRooms query (#6317)
1 parent e96ce35 commit 2e26ba8

File tree

4 files changed

+107
-13
lines changed

4 files changed

+107
-13
lines changed

_schemaV2.graphql

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17609,17 +17609,10 @@ type Query {
1760917609

1761017610
# (Deprecate) use viewingRoomsConnection
1761117611
viewingRooms(
17612-
# Returns the elements in the list that come after the specified cursor.
1761317612
after: String
17614-
17615-
# Returns the elements in the list that come before the specified cursor.
1761617613
before: String
1761717614
featured: Boolean
17618-
17619-
# Returns the first _n_ elements from the list.
1762017615
first: Int
17621-
17622-
# Returns the last _n_ elements from the list.
1762317616
last: Int
1762417617
partnerID: ID
1762517618

@@ -22172,6 +22165,22 @@ type Viewer {
2217222165

2217322166
# Find a viewing room by ID
2217422167
viewingRoom(id: ID!): ViewingRoom
22168+
22169+
# (Deprecate) use viewingRoomsConnection
22170+
viewingRooms(
22171+
after: String
22172+
before: String
22173+
featured: Boolean
22174+
first: Int
22175+
last: Int
22176+
partnerID: ID
22177+
22178+
# (Deprecated) Use statuses
22179+
published: Boolean
22180+
22181+
# Returns only viewing rooms with these statuses
22182+
statuses: [ViewingRoomStatusEnum!] = [live]
22183+
): ViewingRoomConnection @deprecated(reason: "Use viewingRoomsConnection")
2217522184
viewingRoomsConnection(
2217622185
after: String
2217722186
before: String
@@ -22273,22 +22282,24 @@ input ViewingRoomAttributes {
2227322282
title: String
2227422283
}
2227522284

22276-
# The connection type for ViewingRoom.
22285+
# A connection to a list of items.
2227722286
type ViewingRoomConnection {
2227822287
# A list of edges.
2227922288
edges: [ViewingRoomEdge]
22289+
pageCursors: PageCursors!
2228022290

2228122291
# Information to aid in pagination.
2228222292
pageInfo: PageInfo!
22283-
22284-
# Total count of matching nodes, before pagination
22285-
totalCount: Int!
22293+
totalCount: Int
2228622294
}
2228722295

2228822296
# An edge in a connection.
2228922297
type ViewingRoomEdge {
22290-
# A cursor for use in pagination.
22298+
# A cursor for use in pagination
2229122299
cursor: String!
22300+
22301+
# The item at the end of the edge
22302+
node: ViewingRoom
2229222303
}
2229322304

2229422305
union ViewingRoomOrErrorsUnion = Errors | ViewingRoom

src/lib/stitching/gravity/schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import config from "config"
1212

1313
const rootFieldsAllowList = ["agreement"].concat(
1414
config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
15-
? ["viewingRooms"]
15+
? []
1616
: ["viewingRoom", "viewingRooms", "viewingRoomsConnection"]
1717
)
1818

@@ -53,8 +53,11 @@ export const executableGravitySchema = () => {
5353
if (config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA) {
5454
duplicatedTypes.push("ViewingRoom")
5555
duplicatedTypes.push("ViewingRoomsConnection")
56+
duplicatedTypes.push("ViewingRoomConnection")
5657
duplicatedTypes.push("ViewingRoomsEdge")
5758
duplicatedTypes.push("ViewingRoomsEdge")
59+
duplicatedTypes.push("ViewingRoomEdge")
60+
duplicatedTypes.push("ViewingRoomEdge")
5861

5962
duplicatedTypes.push("CreateViewingRoomPayload")
6063
duplicatedTypes.push("CreateViewingRoomInput")

src/schema/v2/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ import { publishViewingRoomMutation } from "./viewingRooms/mutations/publishView
267267
import { unpublishViewingRoomMutation } from "./viewingRooms/mutations/unpublishViewingRoomMutation"
268268
import { updateViewingRoomArtworksMutation } from "./viewingRooms/mutations/updateViewingRoomArtworks"
269269
import { updateViewingRoomSubsectionsMutation } from "./viewingRooms/mutations/updateViewingRoomSubsections"
270+
import { ViewingRoomConnection } from "./viewingRooms"
270271

271272
const viewingRoomUnstitchedRootField = config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
272273
? {
273274
viewingRoom: ViewingRoom,
274275
viewingRoomsConnection: ViewingRoomsConnection,
276+
viewingRooms: ViewingRoomConnection,
275277
}
276278
: ({} as any)
277279

src/schema/v2/viewingRooms.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {
2+
GraphQLBoolean,
3+
GraphQLFieldConfig,
4+
GraphQLID,
5+
GraphQLList,
6+
GraphQLNonNull,
7+
} from "graphql"
8+
import { ResolverContext } from "types/graphql"
9+
import {
10+
connectionWithCursorInfo,
11+
paginationResolver,
12+
} from "./fields/pagination"
13+
import { ViewingRoomType } from "./viewingRoom"
14+
import { pageable } from "relay-cursor-paging"
15+
import { convertConnectionArgsToGravityArgs } from "lib/helpers"
16+
import { ViewingRoomStatusEnum } from "./viewingRoomConnection"
17+
18+
const ViewingRoomConnectionType = connectionWithCursorInfo({
19+
name: "ViewingRoom",
20+
nodeType: ViewingRoomType,
21+
})
22+
23+
export const ViewingRoomConnection: GraphQLFieldConfig<
24+
void,
25+
ResolverContext
26+
> = {
27+
type: ViewingRoomConnectionType.connectionType,
28+
description: "(Deprecate) use viewingRoomsConnection",
29+
deprecationReason: "Use viewingRoomsConnection",
30+
args: pageable({
31+
featured: {
32+
type: GraphQLBoolean,
33+
},
34+
partnerID: {
35+
type: GraphQLID,
36+
},
37+
published: {
38+
type: GraphQLBoolean,
39+
description: "(Deprecated) Use statuses",
40+
},
41+
statuses: {
42+
type: new GraphQLList(new GraphQLNonNull(ViewingRoomStatusEnum)),
43+
defaultValue: ["live"],
44+
description: "Returns only viewing rooms with these statuses",
45+
},
46+
}),
47+
resolve: async (_root, args, { viewingRoomsLoader }) => {
48+
// TODO: Currently clients do not specify `first` and expect 20 viewing rooms in response.
49+
// This should be removed once clients are updated.
50+
if (!args.first) {
51+
args.first = 20
52+
}
53+
54+
const { page, size, offset } = convertConnectionArgsToGravityArgs(args)
55+
56+
const gravityArgs = {
57+
partner_id: args.partnerID,
58+
featured: args.featured,
59+
statuses: args.statuses,
60+
page,
61+
size,
62+
total_count: true,
63+
}
64+
65+
const { body, headers } = await viewingRoomsLoader(gravityArgs)
66+
67+
const totalCount = parseInt(headers["x-total-count"] || "0", 10)
68+
69+
return paginationResolver({
70+
args,
71+
body,
72+
offset,
73+
page,
74+
size,
75+
totalCount,
76+
})
77+
},
78+
}

0 commit comments

Comments
 (0)