-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathMarketingCollectionHitNotificationItem.ts
47 lines (41 loc) · 1.53 KB
/
MarketingCollectionHitNotificationItem.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { GraphQLObjectType } from "graphql"
import { connectionFromArray } from "graphql-relay"
import { convertConnectionArgsToGravityArgs } from "lib/helpers"
import { pageable } from "relay-cursor-paging"
import { artworkConnection } from "schema/v2/artwork"
import { createPageCursors } from "schema/v2/fields/pagination"
import { MarketingCollectionType } from "schema/v2/marketingCollections"
import { ResolverContext } from "types/graphql"
export const MarketingCollectionHitNotificationItemType = new GraphQLObjectType<
any,
ResolverContext
>({
name: "MarketingCollectionHitNotificationItem",
fields: {
marketingCollection: {
type: MarketingCollectionType,
resolve: ({ actor_ids }, _args, { marketingCollectionLoader }) => {
if (!marketingCollectionLoader) {
throw new Error("You need to be signed in to perform this action")
}
if (!actor_ids) return null
const collectionID = actor_ids[0]
return marketingCollectionLoader(collectionID)
},
},
artworksConnection: {
type: artworkConnection.connectionType,
args: pageable(),
resolve: async ({ object_ids }, args, { artworksLoader }) => {
const { page, size } = convertConnectionArgsToGravityArgs(args)
const body = await artworksLoader({ ids: object_ids })
const totalCount = body.length
return {
totalCount,
pageCursors: createPageCursors({ page, size }, totalCount),
...connectionFromArray(body, args),
}
},
},
},
})