From 2a95760b37e76d4bf0a7b765308f1ce1ebafdbc9 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Fri, 21 Jun 2024 16:02:23 -0400 Subject: [PATCH 01/13] Starts exposing partner search criteria data from gravity Co-authored-by: Lily Pace --- _schemaV2.graphql | 41 +++++++++++ .../loaders_with_authentication/gravity.ts | 5 ++ src/schema/v2/Alerts/index.ts | 7 ++ src/schema/v2/fields/pagination.ts | 10 +++ .../v2/partner/__tests__/partner.test.js | 61 ++++++++++++++++ src/schema/v2/partner/partner.ts | 71 +++++++++++++++++++ 6 files changed, 195 insertions(+) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index 7fd1f0e098..c0b45171d3 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14682,6 +14682,15 @@ type Partner implements Node { ): LocationConnection meta: PartnerMeta name: String + partnerAlertsConnection( + after: String + before: String + first: Int + last: Int + page: Int + size: Int + totalCount: Boolean + ): PartnerAlertsConnection partnerPageEligible: Boolean partnerType: String profile: Profile @@ -14755,6 +14764,38 @@ type PartnerAgreement { # A partner agreement or errors object union PartnerAgreementOrErrorsUnion = Errors | PartnerAgreement +type PartnerAlert { + artist_id: String + created_at: String + id: String + matched_at: String + partner_id: String + score: String + search_criteria_id: String + updated_at: String + user_ids: [String] +} + +# A connection to a list of items. +type PartnerAlertsConnection { + # A list of edges. + edges: [PartnerAlertsEdge] + pageCursors: PageCursors! + + # Information to aid in pagination. + pageInfo: PageInfo! + totalCount: Int +} + +# An edge in a connection. +type PartnerAlertsEdge { + # A cursor for use in pagination + cursor: String! + + # The item at the end of the edge + node: PartnerAlert +} + type PartnerArtist { artist: Artist artworksConnection( diff --git a/src/lib/loaders/loaders_with_authentication/gravity.ts b/src/lib/loaders/loaders_with_authentication/gravity.ts index 9299ba4929..83d821c986 100644 --- a/src/lib/loaders/loaders_with_authentication/gravity.ts +++ b/src/lib/loaders/loaders_with_authentication/gravity.ts @@ -643,6 +643,11 @@ export default (accessToken, userID, opts) => { {}, { headers: true } ), + partnerSearchCriteriaLoader: gravityLoader( + (id) => `/partner/${id}/partner_search_criterias`, + {}, + { headers: true } + ), partnerShowsLoader: gravityLoader( (partner_id) => `partner/${partner_id}/shows`, {}, diff --git a/src/schema/v2/Alerts/index.ts b/src/schema/v2/Alerts/index.ts index 73f93201ea..732d74db7e 100644 --- a/src/schema/v2/Alerts/index.ts +++ b/src/schema/v2/Alerts/index.ts @@ -440,6 +440,13 @@ export const AlertsConnectionType = connectionWithCursorInfo({ edgeFields: AlertsEdgeFields, }).connectionType +export const PartnerAlertsSummaryFields = { + id: { + type: AlertType, + resolve: ({ id }) => id, + }, +} + export const AlertsSummaryFields = { topHit: { type: AlertType, diff --git a/src/schema/v2/fields/pagination.ts b/src/schema/v2/fields/pagination.ts index 65a9da648c..72c1307a83 100644 --- a/src/schema/v2/fields/pagination.ts +++ b/src/schema/v2/fields/pagination.ts @@ -83,6 +83,7 @@ function pageToCursorObject(page, currentPage, size) { // Returns an array of PageCursor objects // from start to end (page numbers). function pageCursorsToArray(start, end, currentPage, size) { + console.log(start, end, currentPage, size) let page const cursors = [] for (page = start; page <= end; page++) { @@ -100,6 +101,9 @@ export function computeTotalPages( pageNumberCap: number | null = PAGE_NUMBER_CAP ) { const totalPages = Math.ceil(totalRecords / size) + console.log("totalRecords", totalRecords) + console.log("size", size) + console.log("TPs", totalPages) return pageNumberCap ? Math.min(totalPages, pageNumberCap) : totalPages } @@ -117,12 +121,16 @@ export function createPageCursors( const totalPages = computeTotalPages(totalRecords, size, pageNumberCap) + console.log("totalpages", totalPages) + console.log("max", max) + let pageCursors // Degenerate case of no records found. if (totalPages === 0) { pageCursors = { around: [pageToCursorObject(1, 1, size)] } } else if (totalPages <= max) { // Collection is short, and `around` includes page 1 and the last page. + console.log("hello??") pageCursors = { around: pageCursorsToArray(1, totalPages, currentPage, size), } @@ -165,6 +173,7 @@ export function createPageCursors( size ) } + console.log(pageCursors) return pageCursors } @@ -221,6 +230,7 @@ export const paginationResolver = ({ ...pick(args, "before", "after", "first", "last"), } + console.log("from the paginationR", body, page, totalCount) return { totalCount, pageCursors: createPageCursors({ page, size }, totalCount), diff --git a/src/schema/v2/partner/__tests__/partner.test.js b/src/schema/v2/partner/__tests__/partner.test.js index 3a43d4fcda..27562e7dcc 100644 --- a/src/schema/v2/partner/__tests__/partner.test.js +++ b/src/schema/v2/partner/__tests__/partner.test.js @@ -1421,6 +1421,67 @@ describe("Partner type", () => { }) }) + describe("#partnerAlertsConnection", () => { + it("returns the summary of artists with recently enabled user search criteria", async () => { + const response = + { + body: { + hits: [ + { + id: '8754ff90-b020-425b-8dae-894ce5ad9d1f', + search_criteria_id: '3f980bbe-7b9b-4fa9-beb1-69d13e94fb0c', + partner_id: '5f80bfefe8d808000ea212c1', + + }, + { + id: 'b4adc50d-a584-4820-9140-4d49d7b6c7dc', + search_criteria_id: '614af56c-88cb-4ea7-bec5-fbdf9b67c24a', + partner_id: '5f80bfefe8d808000ea212c1', + }, + ], + }, + headers: { + "x-total-count": 1, + }, + } + + const query = gql` + { + partner(id: "catty-partner") { + partnerAlertsConnection(first: 10) { + edges { + node { + id + } + } + } + } + } + ` + const partnerSearchCriteriaLoader = () => Promise.resolve(response) + const data = await runAuthenticatedQuery(query, { + ...context, + partnerSearchCriteriaLoader, + }) + + // TODO: WHY ONLY ONE BEING RETURNED + // {"partner": {"partnerAlertsConnection": {"edges": [{"node": {"id": "8754ff90-b020-425b-8dae-894ce5ad9d1f"}}]}}} + expect(data).toEqual({ + partner: { + partnerAlertsConnection: { + edges: [ + { + node: { + id: "8754ff90-b020-425b-8dae-894ce5ad9d1f", + }, + }, + ], + }, + }, + }) + }) + }) + describe("#alertsSummaryArtistsConnection", () => { it("returns the summary of artists with recently enabled user search criteria", async () => { const summaryResponse = { diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index 591531593d..297f50c139 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -154,6 +154,27 @@ export const PartnerType = new GraphQLObjectType({ nodeType: ArtistType, }).connectionType + const PartnerAlertType = new GraphQLObjectType({ + name: "PartnerAlert", + fields: { + id: { type: GraphQLString }, + search_criteria_id: { type: GraphQLString }, + partner_id: { type: GraphQLString }, + score: { type: GraphQLString }, + matched_at: { type: GraphQLString }, + created_at: { type: GraphQLString }, + updated_at: { type: GraphQLString }, + user_ids: { type: new GraphQLList(GraphQLString) }, + artist_id: { type: GraphQLString }, + }, + }) + + const PartnerAlertsConnectionType = connectionWithCursorInfo({ + name: "PartnerAlerts", + // edgeFields: PartnerAlertsSummaryFields, + nodeType: PartnerAlertType, + }).connectionType + return { ...SlugAndInternalIDFields, cached, @@ -222,6 +243,56 @@ export const PartnerType = new GraphQLObjectType({ }) }, }, + partnerAlertsConnection: { + type: PartnerAlertsConnectionType, + args: pageable({ + page: { + type: GraphQLInt, + }, + size: { + type: GraphQLInt, + }, + totalCount: { + type: GraphQLBoolean, + }, + }), + resolve: async ({ _id }, args, { partnerSearchCriteriaLoader }) => { + if (!partnerSearchCriteriaLoader) return null + const { page, size, offset } = convertConnectionArgsToGravityArgs( + args + ) + + type GravityArgs = { + page: number + size: number + total_count: number + } + + const gravityArgs: GravityArgs = { + page, + size, + total_count: args.totalCount, + } + + const { body, headers } = await partnerSearchCriteriaLoader?.( + _id, + gravityArgs + ) + + const totalCount = parseInt(headers["x-total-count"] || "0", 10) + + // TODO: Fix paginationResolver, do we need gravity level defaults? + return paginationResolver({ + totalCount, + offset, + page, + size, + body: body.hits, + args, + resolveNode: (node) => node, + }) + }, + }, articlesConnection: { description: "A connection of articles related to a partner.", type: articleConnection.connectionType, From de901c82143a69632f9d15a7371c5808f71ec26c Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Tue, 25 Jun 2024 12:05:52 -0400 Subject: [PATCH 02/13] Adjust tests to return correct amount of nodes Co-authored-by: Lily Pace --- src/schema/v2/fields/pagination.ts | 10 ---------- src/schema/v2/partner/__tests__/partner.test.js | 10 ++++++---- src/schema/v2/partner/partner.ts | 1 - 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/schema/v2/fields/pagination.ts b/src/schema/v2/fields/pagination.ts index 72c1307a83..65a9da648c 100644 --- a/src/schema/v2/fields/pagination.ts +++ b/src/schema/v2/fields/pagination.ts @@ -83,7 +83,6 @@ function pageToCursorObject(page, currentPage, size) { // Returns an array of PageCursor objects // from start to end (page numbers). function pageCursorsToArray(start, end, currentPage, size) { - console.log(start, end, currentPage, size) let page const cursors = [] for (page = start; page <= end; page++) { @@ -101,9 +100,6 @@ export function computeTotalPages( pageNumberCap: number | null = PAGE_NUMBER_CAP ) { const totalPages = Math.ceil(totalRecords / size) - console.log("totalRecords", totalRecords) - console.log("size", size) - console.log("TPs", totalPages) return pageNumberCap ? Math.min(totalPages, pageNumberCap) : totalPages } @@ -121,16 +117,12 @@ export function createPageCursors( const totalPages = computeTotalPages(totalRecords, size, pageNumberCap) - console.log("totalpages", totalPages) - console.log("max", max) - let pageCursors // Degenerate case of no records found. if (totalPages === 0) { pageCursors = { around: [pageToCursorObject(1, 1, size)] } } else if (totalPages <= max) { // Collection is short, and `around` includes page 1 and the last page. - console.log("hello??") pageCursors = { around: pageCursorsToArray(1, totalPages, currentPage, size), } @@ -173,7 +165,6 @@ export function createPageCursors( size ) } - console.log(pageCursors) return pageCursors } @@ -230,7 +221,6 @@ export const paginationResolver = ({ ...pick(args, "before", "after", "first", "last"), } - console.log("from the paginationR", body, page, totalCount) return { totalCount, pageCursors: createPageCursors({ page, size }, totalCount), diff --git a/src/schema/v2/partner/__tests__/partner.test.js b/src/schema/v2/partner/__tests__/partner.test.js index 27562e7dcc..3bf3ad74a7 100644 --- a/src/schema/v2/partner/__tests__/partner.test.js +++ b/src/schema/v2/partner/__tests__/partner.test.js @@ -1441,7 +1441,7 @@ describe("Partner type", () => { ], }, headers: { - "x-total-count": 1, + "x-total-count": 2, }, } @@ -1463,9 +1463,6 @@ describe("Partner type", () => { ...context, partnerSearchCriteriaLoader, }) - - // TODO: WHY ONLY ONE BEING RETURNED - // {"partner": {"partnerAlertsConnection": {"edges": [{"node": {"id": "8754ff90-b020-425b-8dae-894ce5ad9d1f"}}]}}} expect(data).toEqual({ partner: { partnerAlertsConnection: { @@ -1475,6 +1472,11 @@ describe("Partner type", () => { id: "8754ff90-b020-425b-8dae-894ce5ad9d1f", }, }, + { + node: { + id: "b4adc50d-a584-4820-9140-4d49d7b6c7dc" + } + } ], }, }, diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index 297f50c139..a410b596e1 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -281,7 +281,6 @@ export const PartnerType = new GraphQLObjectType({ const totalCount = parseInt(headers["x-total-count"] || "0", 10) - // TODO: Fix paginationResolver, do we need gravity level defaults? return paginationResolver({ totalCount, offset, From 4ac3f12a29f8474561221a12c58779be45095242 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Fri, 28 Jun 2024 13:24:47 -0400 Subject: [PATCH 03/13] Start fetching PSC.collector profile --- _schemaV2.graphql | 27 +++++++ .../loaders_with_authentication/gravity.ts | 7 ++ src/schema/v2/partner/partner.ts | 79 +++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index c0b45171d3..6dc3be9c31 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14682,6 +14682,13 @@ type Partner implements Node { ): LocationConnection meta: PartnerMeta name: String + partnerAlertsCollectorProfilesConnection( + after: String + before: String + first: Int + last: Int + partnerSearchCriteriaId: String + ): PartnerAlertsCollectorProfilesConnection partnerAlertsConnection( after: String before: String @@ -14776,6 +14783,26 @@ type PartnerAlert { user_ids: [String] } +# A connection to a list of items. +type PartnerAlertsCollectorProfilesConnection { + # A list of edges. + edges: [PartnerAlertsCollectorProfilesEdge] + pageCursors: PageCursors! + + # Information to aid in pagination. + pageInfo: PageInfo! + totalCount: Int +} + +# An edge in a connection. +type PartnerAlertsCollectorProfilesEdge { + # A cursor for use in pagination + cursor: String! + + # The item at the end of the edge + node: CollectorProfileType +} + # A connection to a list of items. type PartnerAlertsConnection { # A list of edges. diff --git a/src/lib/loaders/loaders_with_authentication/gravity.ts b/src/lib/loaders/loaders_with_authentication/gravity.ts index 83d821c986..4b1c09727c 100644 --- a/src/lib/loaders/loaders_with_authentication/gravity.ts +++ b/src/lib/loaders/loaders_with_authentication/gravity.ts @@ -648,6 +648,13 @@ export default (accessToken, userID, opts) => { {}, { headers: true } ), + partnerSearchCriteriaCollectorProfilesLoader: gravityLoader< + any, + { partnerId: string; partnerSearchCriteriaId: string } + >( + ({ partnerId, partnerSearchCriteriaId }) => + `partner/${partnerId}/partner_search_criterias/${partnerSearchCriteriaId}/users` + ), partnerShowsLoader: gravityLoader( (partner_id) => `partner/${partner_id}/shows`, {}, diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index a410b596e1..bfe27fee30 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -51,6 +51,7 @@ import { ArtworkVisibility, ArtworkVisibilityEnumValues, } from "schema/v2/artwork/artworkVisibility" +import { CollectorProfileType } from "../CollectorProfile/collectorProfile" const isFairOrganizer = (type) => type === "FairOrganizer" const isGallery = (type) => type === "PartnerGallery" @@ -175,6 +176,13 @@ export const PartnerType = new GraphQLObjectType({ nodeType: PartnerAlertType, }).connectionType + const PartnerAlertsCollectorProfilesConnectionType = connectionWithCursorInfo( + { + name: "PartnerAlertsCollectorProfiles", + nodeType: CollectorProfileType, + } + ).connectionType + return { ...SlugAndInternalIDFields, cached, @@ -243,6 +251,77 @@ export const PartnerType = new GraphQLObjectType({ }) }, }, + partnerAlertsCollectorProfilesConnection: { + type: PartnerAlertsCollectorProfilesConnectionType, + args: pageable({ + partnerSearchCriteriaId: { + type: GraphQLString, + }, + }), + // partnerSearchCriteriaCollectorProfilesLoader + resolve: async ( + { _id }, + args, + { partnerSearchCriteriaCollectorProfilesLoader } + ) => { + if (!partnerSearchCriteriaCollectorProfilesLoader) return null + const { page, size, offset } = convertConnectionArgsToGravityArgs( + args + ) + + console.log("were args", args) + + type GravityArgs = { + page: number + size: number + total_count: number + partner_search_criteria_id: string + } + + const gravityArgs: GravityArgs = { + page, + size, + total_count: args.totalCount, + partner_search_criteria_id: args.partnerSearchCriteriaId, + } + + // const { results, count } = await articlesLoader(articleArgs) + const data = await partnerSearchCriteriaCollectorProfilesLoader?.({ + partnerId: _id, + partnerSearchCriteriaId: args.partnerSearchCriteriaId, + }) + + console.log("CP endpoint", data) + console.log("CP count", data.collector_profiles.length) + + // totalCount: count, + // pageCursors: createPageCursors({ ...args, page, size }, count), + // ...connectionFromArraySlice(results, args, { + // arrayLength: count, + // sliceStart: offset, + // }), + + return { + totalCount: 10, + pageCursors: createPageCursors({ ...args, page, size }, 10), + ...connectionFromArraySlice(data.collector_profiles, args, { + arrayLength: 10, + sliceStart: offset, + }), + } + + // const totalCount = parseInt(headers["x-total-count"] || "0", 10) + + // return paginationResolver({ + // offset, + // page, + // size, + // body: body.collector_profiles, + // args, + // resolveNode: (node) => node, + // }) + }, + }, partnerAlertsConnection: { type: PartnerAlertsConnectionType, args: pageable({ From 37143cf16ecfce1e01f15bf23fa70b1727f5fc33 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Tue, 2 Jul 2024 12:05:27 -0400 Subject: [PATCH 04/13] Spike: wire in new gravity bulk collectorprofiles endpoint --- _schemaV2.graphql | 19 ++-- .../loaders_with_authentication/gravity.ts | 13 ++- src/schema/v2/partner/partner.ts | 97 ++++++++++++++++--- 3 files changed, 104 insertions(+), 25 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index 6dc3be9c31..74e680e0fa 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14772,15 +14772,20 @@ type PartnerAgreement { union PartnerAgreementOrErrorsUnion = Errors | PartnerAgreement type PartnerAlert { - artist_id: String - created_at: String + artistId: String + collectorProfilesConnection( + after: String + before: String + first: Int + last: Int + totalCount: Boolean + ): PartnerAlertsCollectorProfilesConnection id: String - matched_at: String - partner_id: String + matchedAt: String + partnerId: String score: String - search_criteria_id: String - updated_at: String - user_ids: [String] + searchCriteriaId: String + userIds: [String] } # A connection to a list of items. diff --git a/src/lib/loaders/loaders_with_authentication/gravity.ts b/src/lib/loaders/loaders_with_authentication/gravity.ts index 4b1c09727c..d33f10571c 100644 --- a/src/lib/loaders/loaders_with_authentication/gravity.ts +++ b/src/lib/loaders/loaders_with_authentication/gravity.ts @@ -650,10 +650,17 @@ export default (accessToken, userID, opts) => { ), partnerSearchCriteriaCollectorProfilesLoader: gravityLoader< any, - { partnerId: string; partnerSearchCriteriaId: string } + { partner_id: string; user_ids: string[] } >( - ({ partnerId, partnerSearchCriteriaId }) => - `partner/${partnerId}/partner_search_criterias/${partnerSearchCriteriaId}/users` + ({ partner_id, user_ids }) => { + console.log("im in") + console.log("partnerid", partner_id) + console.log("userIds", user_ids) + const userIdsParams = user_ids.map((id) => `user_ids[]=${id}`).join("&") + return `/partner_collector_profiles?partner_id=${partner_id}&${userIdsParams}` + }, + {}, + { headers: true } ), partnerShowsLoader: gravityLoader( (partner_id) => `partner/${partner_id}/shows`, diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index bfe27fee30..d447f26fe3 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -155,18 +155,93 @@ export const PartnerType = new GraphQLObjectType({ nodeType: ArtistType, }).connectionType + const PartnerAlertsCollectorProfilesConnectionType = connectionWithCursorInfo( + { + name: "PartnerAlertsCollectorProfiles", + nodeType: CollectorProfileType, + } + ).connectionType + const PartnerAlertType = new GraphQLObjectType({ name: "PartnerAlert", fields: { id: { type: GraphQLString }, - search_criteria_id: { type: GraphQLString }, - partner_id: { type: GraphQLString }, + searchCriteriaId: { + type: GraphQLString, + resolve: ({ search_criteria_id }) => search_criteria_id, + }, + partnerId: { + type: GraphQLString, + resolve: ({ partner_id }) => partner_id, + }, score: { type: GraphQLString }, - matched_at: { type: GraphQLString }, - created_at: { type: GraphQLString }, - updated_at: { type: GraphQLString }, - user_ids: { type: new GraphQLList(GraphQLString) }, - artist_id: { type: GraphQLString }, + matchedAt: { + type: GraphQLString, + resolve: ({ matched_at }) => matched_at, + }, + userIds: { + type: new GraphQLList(GraphQLString), + resolve: ({ user_ids }) => user_ids, + }, + artistId: { + type: GraphQLString, + resolve: ({ artist_id }) => artist_id, + }, + collectorProfilesConnection: { + type: PartnerAlertsCollectorProfilesConnectionType, + args: pageable({ + totalCount: { + type: GraphQLBoolean, + }, + }), + resolve: async ( + parent, + args, + { partnerSearchCriteriaCollectorProfilesLoader } + ) => { + if (!partnerSearchCriteriaCollectorProfilesLoader) return null + + const { page, size, offset } = convertConnectionArgsToGravityArgs( + args + ) + console.log(args) + console.log("parent", parent) + + // TODO: Add typing and fix casing + const gravityArgs = { + page, + size, + total_count: args.totalCount, + partner_id: parent.partner_id, + user_ids: parent.user_ids, + } + + console.log(gravityArgs) + + const data = await partnerSearchCriteriaCollectorProfilesLoader( + gravityArgs + ) + + const collectorProfiles = data.body.flatMap((item) => + item.collector_profile ? [item.collector_profile].flat() : [] + ) + + console.log(data) + console.log("CP:", collectorProfiles) + + return { + totalCount: collectorProfiles.length, + pageCursors: createPageCursors( + { ...args, page, size }, + collectorProfiles.length + ), + ...connectionFromArraySlice(collectorProfiles, args, { + arrayLength: collectorProfiles.length, + sliceStart: offset, + }), + } + }, + }, }, }) @@ -176,13 +251,6 @@ export const PartnerType = new GraphQLObjectType({ nodeType: PartnerAlertType, }).connectionType - const PartnerAlertsCollectorProfilesConnectionType = connectionWithCursorInfo( - { - name: "PartnerAlertsCollectorProfiles", - nodeType: CollectorProfileType, - } - ).connectionType - return { ...SlugAndInternalIDFields, cached, @@ -285,7 +353,6 @@ export const PartnerType = new GraphQLObjectType({ partner_search_criteria_id: args.partnerSearchCriteriaId, } - // const { results, count } = await articlesLoader(articleArgs) const data = await partnerSearchCriteriaCollectorProfilesLoader?.({ partnerId: _id, partnerSearchCriteriaId: args.partnerSearchCriteriaId, From 73c323fae5ab783eb497a4c75ef2ee67310503f0 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Wed, 3 Jul 2024 12:13:18 -0400 Subject: [PATCH 05/13] Start cleaning up notes and refactor --- _schemaV2.graphql | 7 --- src/schema/v2/partner/partner.ts | 91 ++++---------------------------- 2 files changed, 10 insertions(+), 88 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index 74e680e0fa..e9d93b1c31 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14682,13 +14682,6 @@ type Partner implements Node { ): LocationConnection meta: PartnerMeta name: String - partnerAlertsCollectorProfilesConnection( - after: String - before: String - first: Int - last: Int - partnerSearchCriteriaId: String - ): PartnerAlertsCollectorProfilesConnection partnerAlertsConnection( after: String before: String diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index d447f26fe3..36b7830e7a 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -204,11 +204,16 @@ export const PartnerType = new GraphQLObjectType({ const { page, size, offset } = convertConnectionArgsToGravityArgs( args ) - console.log(args) - console.log("parent", parent) - // TODO: Add typing and fix casing - const gravityArgs = { + type GravityArgs = { + page: number + size: number + partner_id: string + user_ids: string[] + total_count?: number + } + + const gravityArgs: GravityArgs = { page, size, total_count: args.totalCount, @@ -216,8 +221,6 @@ export const PartnerType = new GraphQLObjectType({ user_ids: parent.user_ids, } - console.log(gravityArgs) - const data = await partnerSearchCriteriaCollectorProfilesLoader( gravityArgs ) @@ -226,9 +229,6 @@ export const PartnerType = new GraphQLObjectType({ item.collector_profile ? [item.collector_profile].flat() : [] ) - console.log(data) - console.log("CP:", collectorProfiles) - return { totalCount: collectorProfiles.length, pageCursors: createPageCursors( @@ -247,7 +247,6 @@ export const PartnerType = new GraphQLObjectType({ const PartnerAlertsConnectionType = connectionWithCursorInfo({ name: "PartnerAlerts", - // edgeFields: PartnerAlertsSummaryFields, nodeType: PartnerAlertType, }).connectionType @@ -319,76 +318,6 @@ export const PartnerType = new GraphQLObjectType({ }) }, }, - partnerAlertsCollectorProfilesConnection: { - type: PartnerAlertsCollectorProfilesConnectionType, - args: pageable({ - partnerSearchCriteriaId: { - type: GraphQLString, - }, - }), - // partnerSearchCriteriaCollectorProfilesLoader - resolve: async ( - { _id }, - args, - { partnerSearchCriteriaCollectorProfilesLoader } - ) => { - if (!partnerSearchCriteriaCollectorProfilesLoader) return null - const { page, size, offset } = convertConnectionArgsToGravityArgs( - args - ) - - console.log("were args", args) - - type GravityArgs = { - page: number - size: number - total_count: number - partner_search_criteria_id: string - } - - const gravityArgs: GravityArgs = { - page, - size, - total_count: args.totalCount, - partner_search_criteria_id: args.partnerSearchCriteriaId, - } - - const data = await partnerSearchCriteriaCollectorProfilesLoader?.({ - partnerId: _id, - partnerSearchCriteriaId: args.partnerSearchCriteriaId, - }) - - console.log("CP endpoint", data) - console.log("CP count", data.collector_profiles.length) - - // totalCount: count, - // pageCursors: createPageCursors({ ...args, page, size }, count), - // ...connectionFromArraySlice(results, args, { - // arrayLength: count, - // sliceStart: offset, - // }), - - return { - totalCount: 10, - pageCursors: createPageCursors({ ...args, page, size }, 10), - ...connectionFromArraySlice(data.collector_profiles, args, { - arrayLength: 10, - sliceStart: offset, - }), - } - - // const totalCount = parseInt(headers["x-total-count"] || "0", 10) - - // return paginationResolver({ - // offset, - // page, - // size, - // body: body.collector_profiles, - // args, - // resolveNode: (node) => node, - // }) - }, - }, partnerAlertsConnection: { type: PartnerAlertsConnectionType, args: pageable({ @@ -411,7 +340,7 @@ export const PartnerType = new GraphQLObjectType({ type GravityArgs = { page: number size: number - total_count: number + total_count?: number } const gravityArgs: GravityArgs = { From 322eb12d850b7ef8dd142b424555c936f74dbd69 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Wed, 3 Jul 2024 15:10:14 -0400 Subject: [PATCH 06/13] Pull out PartnerAlertType into seperate file --- _schemaV2.graphql | 42 ++++---- .../loaders_with_authentication/gravity.ts | 5 +- src/schema/v2/Alerts/index.ts | 7 -- src/schema/v2/partner/partner.ts | 93 +---------------- src/schema/v2/partner/partnerAlerts.ts | 99 +++++++++++++++++++ 5 files changed, 122 insertions(+), 124 deletions(-) create mode 100644 src/schema/v2/partner/partnerAlerts.ts diff --git a/_schemaV2.graphql b/_schemaV2.graphql index e9d93b1c31..bbd5cda949 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14772,7 +14772,7 @@ type PartnerAlert { first: Int last: Int totalCount: Boolean - ): PartnerAlertsCollectorProfilesConnection + ): PartnerCollectorProfilesConnection id: String matchedAt: String partnerId: String @@ -14781,26 +14781,6 @@ type PartnerAlert { userIds: [String] } -# A connection to a list of items. -type PartnerAlertsCollectorProfilesConnection { - # A list of edges. - edges: [PartnerAlertsCollectorProfilesEdge] - pageCursors: PageCursors! - - # Information to aid in pagination. - pageInfo: PageInfo! - totalCount: Int -} - -# An edge in a connection. -type PartnerAlertsCollectorProfilesEdge { - # A cursor for use in pagination - cursor: String! - - # The item at the end of the edge - node: CollectorProfileType -} - # A connection to a list of items. type PartnerAlertsConnection { # A list of edges. @@ -15037,6 +15017,26 @@ enum PartnerClassification { PRIVATE_DEALER } +# A connection to a list of items. +type PartnerCollectorProfilesConnection { + # A list of edges. + edges: [PartnerCollectorProfilesEdge] + pageCursors: PageCursors! + + # Information to aid in pagination. + pageInfo: PageInfo! + totalCount: Int +} + +# An edge in a connection. +type PartnerCollectorProfilesEdge { + # A cursor for use in pagination + cursor: String! + + # The item at the end of the edge + node: CollectorProfileType +} + # A connection to a list of items. type PartnerConnection { # A list of edges. diff --git a/src/lib/loaders/loaders_with_authentication/gravity.ts b/src/lib/loaders/loaders_with_authentication/gravity.ts index d33f10571c..f16317443d 100644 --- a/src/lib/loaders/loaders_with_authentication/gravity.ts +++ b/src/lib/loaders/loaders_with_authentication/gravity.ts @@ -648,14 +648,11 @@ export default (accessToken, userID, opts) => { {}, { headers: true } ), - partnerSearchCriteriaCollectorProfilesLoader: gravityLoader< + partnerCollectorProfilesLoader: gravityLoader< any, { partner_id: string; user_ids: string[] } >( ({ partner_id, user_ids }) => { - console.log("im in") - console.log("partnerid", partner_id) - console.log("userIds", user_ids) const userIdsParams = user_ids.map((id) => `user_ids[]=${id}`).join("&") return `/partner_collector_profiles?partner_id=${partner_id}&${userIdsParams}` }, diff --git a/src/schema/v2/Alerts/index.ts b/src/schema/v2/Alerts/index.ts index 732d74db7e..73f93201ea 100644 --- a/src/schema/v2/Alerts/index.ts +++ b/src/schema/v2/Alerts/index.ts @@ -440,13 +440,6 @@ export const AlertsConnectionType = connectionWithCursorInfo({ edgeFields: AlertsEdgeFields, }).connectionType -export const PartnerAlertsSummaryFields = { - id: { - type: AlertType, - resolve: ({ id }) => id, - }, -} - export const AlertsSummaryFields = { topHit: { type: AlertType, diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index 36b7830e7a..c76d26b89e 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -51,7 +51,7 @@ import { ArtworkVisibility, ArtworkVisibilityEnumValues, } from "schema/v2/artwork/artworkVisibility" -import { CollectorProfileType } from "../CollectorProfile/collectorProfile" +import { PartnerAlertType } from "./partnerAlerts" const isFairOrganizer = (type) => type === "FairOrganizer" const isGallery = (type) => type === "PartnerGallery" @@ -155,96 +155,6 @@ export const PartnerType = new GraphQLObjectType({ nodeType: ArtistType, }).connectionType - const PartnerAlertsCollectorProfilesConnectionType = connectionWithCursorInfo( - { - name: "PartnerAlertsCollectorProfiles", - nodeType: CollectorProfileType, - } - ).connectionType - - const PartnerAlertType = new GraphQLObjectType({ - name: "PartnerAlert", - fields: { - id: { type: GraphQLString }, - searchCriteriaId: { - type: GraphQLString, - resolve: ({ search_criteria_id }) => search_criteria_id, - }, - partnerId: { - type: GraphQLString, - resolve: ({ partner_id }) => partner_id, - }, - score: { type: GraphQLString }, - matchedAt: { - type: GraphQLString, - resolve: ({ matched_at }) => matched_at, - }, - userIds: { - type: new GraphQLList(GraphQLString), - resolve: ({ user_ids }) => user_ids, - }, - artistId: { - type: GraphQLString, - resolve: ({ artist_id }) => artist_id, - }, - collectorProfilesConnection: { - type: PartnerAlertsCollectorProfilesConnectionType, - args: pageable({ - totalCount: { - type: GraphQLBoolean, - }, - }), - resolve: async ( - parent, - args, - { partnerSearchCriteriaCollectorProfilesLoader } - ) => { - if (!partnerSearchCriteriaCollectorProfilesLoader) return null - - const { page, size, offset } = convertConnectionArgsToGravityArgs( - args - ) - - type GravityArgs = { - page: number - size: number - partner_id: string - user_ids: string[] - total_count?: number - } - - const gravityArgs: GravityArgs = { - page, - size, - total_count: args.totalCount, - partner_id: parent.partner_id, - user_ids: parent.user_ids, - } - - const data = await partnerSearchCriteriaCollectorProfilesLoader( - gravityArgs - ) - - const collectorProfiles = data.body.flatMap((item) => - item.collector_profile ? [item.collector_profile].flat() : [] - ) - - return { - totalCount: collectorProfiles.length, - pageCursors: createPageCursors( - { ...args, page, size }, - collectorProfiles.length - ), - ...connectionFromArraySlice(collectorProfiles, args, { - arrayLength: collectorProfiles.length, - sliceStart: offset, - }), - } - }, - }, - }, - }) - const PartnerAlertsConnectionType = connectionWithCursorInfo({ name: "PartnerAlerts", nodeType: PartnerAlertType, @@ -353,7 +263,6 @@ export const PartnerType = new GraphQLObjectType({ _id, gravityArgs ) - const totalCount = parseInt(headers["x-total-count"] || "0", 10) return paginationResolver({ diff --git a/src/schema/v2/partner/partnerAlerts.ts b/src/schema/v2/partner/partnerAlerts.ts new file mode 100644 index 0000000000..cb9d1e9ba8 --- /dev/null +++ b/src/schema/v2/partner/partnerAlerts.ts @@ -0,0 +1,99 @@ +import { pageable } from "relay-cursor-paging" +import { + GraphQLString, + GraphQLObjectType, + GraphQLList, + GraphQLBoolean, +} from "graphql" +import { + connectionWithCursorInfo, + createPageCursors, +} from "schema/v2/fields/pagination" +import { connectionFromArraySlice } from "graphql-relay" +import { convertConnectionArgsToGravityArgs } from "lib/helpers" +import { CollectorProfileType } from "schema/v2/CollectorProfile/collectorProfile" + +const PartnerCollectorProfilesConnectionType = connectionWithCursorInfo({ + name: "PartnerCollectorProfiles", + nodeType: CollectorProfileType, +}).connectionType + +export const PartnerAlertType = new GraphQLObjectType({ + name: "PartnerAlert", + fields: { + id: { type: GraphQLString }, + searchCriteriaId: { + type: GraphQLString, + resolve: ({ search_criteria_id }) => search_criteria_id, + }, + partnerId: { + type: GraphQLString, + resolve: ({ partner_id }) => partner_id, + }, + score: { type: GraphQLString }, + matchedAt: { + type: GraphQLString, + resolve: ({ matched_at }) => matched_at, + }, + userIds: { + type: new GraphQLList(GraphQLString), + resolve: ({ user_ids }) => user_ids, + }, + artistId: { + type: GraphQLString, + resolve: ({ artist_id }) => artist_id, + }, + collectorProfilesConnection: { + type: PartnerCollectorProfilesConnectionType, + args: pageable({ + totalCount: { + type: GraphQLBoolean, + }, + }), + resolve: async (parent, args, { partnerCollectorProfilesLoader }) => { + if (!partnerCollectorProfilesLoader) return null + + const { page, size, offset } = convertConnectionArgsToGravityArgs(args) + + console.log("inside seconds api call") + type GravityArgs = { + page: number + size: number + partner_id: string + user_ids: string[] + total_count?: number + } + + const gravityArgs: GravityArgs = { + page, + size, + total_count: args.totalCount, + partner_id: parent.partner_id, + user_ids: parent.user_ids, + } + + const data = await partnerCollectorProfilesLoader(gravityArgs) + + console.log("data", data) + + const collectorProfiles = data.body.flatMap((item) => + item.collector_profile ? [item.collector_profile].flat() : [] + ) + + return { + totalCount: collectorProfiles.length, + pageCursors: createPageCursors( + { ...args, page, size }, + collectorProfiles.length + ), + ...connectionFromArraySlice(collectorProfiles, args, { + arrayLength: collectorProfiles.length, + sliceStart: offset, + }), + } + }, + }, + }, +}) + +// export default PartnerAlertType From 1af84225c5b27db7559947f2abb54b5ef01caaba Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Mon, 8 Jul 2024 10:05:56 -0400 Subject: [PATCH 07/13] Remove totalCount as an arg and default to true --- _schemaV2.graphql | 1 - src/schema/v2/partner/partner.ts | 7 ++----- src/schema/v2/partner/partnerAlerts.ts | 7 ++----- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index bbd5cda949..a68ebf675f 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14689,7 +14689,6 @@ type Partner implements Node { last: Int page: Int size: Int - totalCount: Boolean ): PartnerAlertsConnection partnerPageEligible: Boolean partnerType: String diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index c76d26b89e..493640cca7 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -237,9 +237,6 @@ export const PartnerType = new GraphQLObjectType({ size: { type: GraphQLInt, }, - totalCount: { - type: GraphQLBoolean, - }, }), resolve: async ({ _id }, args, { partnerSearchCriteriaLoader }) => { if (!partnerSearchCriteriaLoader) return null @@ -250,13 +247,13 @@ export const PartnerType = new GraphQLObjectType({ type GravityArgs = { page: number size: number - total_count?: number + total_count: boolean } const gravityArgs: GravityArgs = { page, size, - total_count: args.totalCount, + total_count: true, } const { body, headers } = await partnerSearchCriteriaLoader?.( diff --git a/src/schema/v2/partner/partnerAlerts.ts b/src/schema/v2/partner/partnerAlerts.ts index cb9d1e9ba8..7c5fd99abd 100644 --- a/src/schema/v2/partner/partnerAlerts.ts +++ b/src/schema/v2/partner/partnerAlerts.ts @@ -55,27 +55,24 @@ export const PartnerAlertType = new GraphQLObjectType({ const { page, size, offset } = convertConnectionArgsToGravityArgs(args) - console.log("inside seconds api call") type GravityArgs = { page: number size: number partner_id: string user_ids: string[] - total_count?: number + total_count?: boolean } const gravityArgs: GravityArgs = { page, size, - total_count: args.totalCount, + total_count: true, partner_id: parent.partner_id, user_ids: parent.user_ids, } const data = await partnerCollectorProfilesLoader(gravityArgs) - console.log("data", data) - const collectorProfiles = data.body.flatMap((item) => item.collector_profile ? [item.collector_profile].flat() : [] ) From 0b3804552a5fe1c3629e88c04cf22a94b43b3b2f Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Mon, 8 Jul 2024 10:43:24 -0400 Subject: [PATCH 08/13] Use paginationResolver and correctly pass Args to Gravity API --- src/schema/v2/partner/partnerAlerts.ts | 49 ++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/schema/v2/partner/partnerAlerts.ts b/src/schema/v2/partner/partnerAlerts.ts index 7c5fd99abd..06b9a076c1 100644 --- a/src/schema/v2/partner/partnerAlerts.ts +++ b/src/schema/v2/partner/partnerAlerts.ts @@ -7,9 +7,8 @@ import { } from "graphql" import { connectionWithCursorInfo, - createPageCursors, + paginationResolver, } from "schema/v2/fields/pagination" -import { connectionFromArraySlice } from "graphql-relay" import { convertConnectionArgsToGravityArgs } from "lib/helpers" import { CollectorProfileType } from "schema/v2/CollectorProfile/collectorProfile" @@ -58,39 +57,45 @@ export const PartnerAlertType = new GraphQLObjectType({ type GravityArgs = { page: number size: number - partner_id: string - user_ids: string[] - total_count?: boolean + offset: number + total_count: boolean } const gravityArgs: GravityArgs = { page, size, + offset, total_count: true, - partner_id: parent.partner_id, - user_ids: parent.user_ids, } - const data = await partnerCollectorProfilesLoader(gravityArgs) + const { partner_id, user_ids } = parent + if (!partner_id || !user_ids) { + throw new Error( + "partnerId or userIds is undefined in the parent object" + ) + } + + const { body, headers } = await partnerCollectorProfilesLoader( + { partner_id, user_ids }, + gravityArgs + ) - const collectorProfiles = data.body.flatMap((item) => + const collectorProfiles = body.flatMap((item) => item.collector_profile ? [item.collector_profile].flat() : [] ) - return { - totalCount: collectorProfiles.length, - pageCursors: createPageCursors( - { ...args, page, size }, - collectorProfiles.length - ), - ...connectionFromArraySlice(collectorProfiles, args, { - arrayLength: collectorProfiles.length, - sliceStart: offset, - }), - } + const totalCount = parseInt(headers["x-total-count"] || "0", 10) + + return paginationResolver({ + totalCount, + offset, + page, + size, + body: collectorProfiles, + args, + resolveNode: (node) => node, + }) }, }, }, }) - -// export default PartnerAlertType From 0dcc65c4e929cc57b6e1e1c72a5e472a626662b8 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Mon, 8 Jul 2024 15:57:21 -0400 Subject: [PATCH 09/13] Fix the dataloader setup for new endpoint, confirm it works with array args --- .../loaders_with_authentication/gravity.ts | 16 +++++--------- src/schema/v2/partner/partnerAlerts.ts | 21 ++++++++++--------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/lib/loaders/loaders_with_authentication/gravity.ts b/src/lib/loaders/loaders_with_authentication/gravity.ts index f16317443d..def2cdd235 100644 --- a/src/lib/loaders/loaders_with_authentication/gravity.ts +++ b/src/lib/loaders/loaders_with_authentication/gravity.ts @@ -597,6 +597,11 @@ export default (accessToken, userID, opts) => { ({ partnerId, userId }) => `partner_collector_profile?partner_id=${partnerId}&user_id=${userId}` ), + partnerCollectorProfilesLoader: gravityLoader( + "partner_collector_profiles", + {}, + { headers: true } + ), partnerCollectorProfileArtworkInquiryCountLoader: gravityLoader< any, { partnerID: string; collectorProfileID: string } @@ -648,17 +653,6 @@ export default (accessToken, userID, opts) => { {}, { headers: true } ), - partnerCollectorProfilesLoader: gravityLoader< - any, - { partner_id: string; user_ids: string[] } - >( - ({ partner_id, user_ids }) => { - const userIdsParams = user_ids.map((id) => `user_ids[]=${id}`).join("&") - return `/partner_collector_profiles?partner_id=${partner_id}&${userIdsParams}` - }, - {}, - { headers: true } - ), partnerShowsLoader: gravityLoader( (partner_id) => `partner/${partner_id}/shows`, {}, diff --git a/src/schema/v2/partner/partnerAlerts.ts b/src/schema/v2/partner/partnerAlerts.ts index 06b9a076c1..c417caebb1 100644 --- a/src/schema/v2/partner/partnerAlerts.ts +++ b/src/schema/v2/partner/partnerAlerts.ts @@ -54,11 +54,20 @@ export const PartnerAlertType = new GraphQLObjectType({ const { page, size, offset } = convertConnectionArgsToGravityArgs(args) + const { partner_id, user_ids } = parent + if (!partner_id || !user_ids) { + throw new Error( + "partnerId or userIds is undefined in the parent object" + ) + } + type GravityArgs = { page: number size: number offset: number total_count: boolean + partner_id: string + user_ids: string[] } const gravityArgs: GravityArgs = { @@ -66,17 +75,11 @@ export const PartnerAlertType = new GraphQLObjectType({ size, offset, total_count: true, - } - - const { partner_id, user_ids } = parent - if (!partner_id || !user_ids) { - throw new Error( - "partnerId or userIds is undefined in the parent object" - ) + partner_id: parent.partner_id, + user_ids: parent.user_ids, } const { body, headers } = await partnerCollectorProfilesLoader( - { partner_id, user_ids }, gravityArgs ) @@ -85,7 +88,6 @@ export const PartnerAlertType = new GraphQLObjectType({ ) const totalCount = parseInt(headers["x-total-count"] || "0", 10) - return paginationResolver({ totalCount, offset, @@ -93,7 +95,6 @@ export const PartnerAlertType = new GraphQLObjectType({ size, body: collectorProfiles, args, - resolveNode: (node) => node, }) }, }, From 64df5b8525833b81d6bf4cbb1b45cf12ca046316 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Tue, 9 Jul 2024 15:54:18 -0400 Subject: [PATCH 10/13] Return Alert for base node and adds Partner specific details to edge --- _schemaV2.graphql | 35 +++--- src/schema/v2/Alerts/index.ts | 29 +++++ .../v2/partner/__tests__/partner.test.js | 17 ++- src/schema/v2/partner/partner.ts | 9 +- src/schema/v2/partner/partnerAlerts.ts | 102 ------------------ 5 files changed, 63 insertions(+), 129 deletions(-) delete mode 100644 src/schema/v2/partner/partnerAlerts.ts diff --git a/_schemaV2.graphql b/_schemaV2.graphql index a68ebf675f..0114cd3443 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14763,23 +14763,6 @@ type PartnerAgreement { # A partner agreement or errors object union PartnerAgreementOrErrorsUnion = Errors | PartnerAgreement -type PartnerAlert { - artistId: String - collectorProfilesConnection( - after: String - before: String - first: Int - last: Int - totalCount: Boolean - ): PartnerCollectorProfilesConnection - id: String - matchedAt: String - partnerId: String - score: String - searchCriteriaId: String - userIds: [String] -} - # A connection to a list of items. type PartnerAlertsConnection { # A list of edges. @@ -14793,11 +14776,27 @@ type PartnerAlertsConnection { # An edge in a connection. type PartnerAlertsEdge { + alert: Alert + artistId: String + collectorProfilesConnection( + after: String + before: String + first: Int + last: Int + totalCount: Boolean + ): PartnerCollectorProfilesConnection + # A cursor for use in pagination cursor: String! + id: String + matchedAt: String # The item at the end of the edge - node: PartnerAlert + node: Alert + partnerId: String + score: String + searchCriteriaId: String + userIds: [String] } type PartnerArtist { diff --git a/src/schema/v2/Alerts/index.ts b/src/schema/v2/Alerts/index.ts index 73f93201ea..493cca038d 100644 --- a/src/schema/v2/Alerts/index.ts +++ b/src/schema/v2/Alerts/index.ts @@ -484,3 +484,32 @@ export const AlertsSummaryFields = { resolve: (resp) => resp, }, } + +export const PartnerAlertsFields = { + id: { type: GraphQLString }, + searchCriteriaId: { + type: GraphQLString, + resolve: ({ search_criteria_id }) => search_criteria_id, + }, + partnerId: { + type: GraphQLString, + resolve: ({ partner_id }) => partner_id, + }, + score: { type: GraphQLString }, + matchedAt: { + type: GraphQLString, + resolve: ({ matched_at }) => matched_at, + }, + alert: { + type: AlertType, + resolve: ({ search_criteria }) => search_criteria, + }, + userIds: { + type: new GraphQLList(GraphQLString), + resolve: ({ user_ids }) => user_ids, + }, + artistId: { + type: GraphQLString, + resolve: ({ artist_id }) => artist_id, + }, +} diff --git a/src/schema/v2/partner/__tests__/partner.test.js b/src/schema/v2/partner/__tests__/partner.test.js index 3bf3ad74a7..f9fc01d4d7 100644 --- a/src/schema/v2/partner/__tests__/partner.test.js +++ b/src/schema/v2/partner/__tests__/partner.test.js @@ -1422,7 +1422,7 @@ describe("Partner type", () => { }) describe("#partnerAlertsConnection", () => { - it("returns the summary of artists with recently enabled user search criteria", async () => { + it("returns partner search criteria details", async () => { const response = { body: { @@ -1431,12 +1431,19 @@ describe("Partner type", () => { id: '8754ff90-b020-425b-8dae-894ce5ad9d1f', search_criteria_id: '3f980bbe-7b9b-4fa9-beb1-69d13e94fb0c', partner_id: '5f80bfefe8d808000ea212c1', - + search_criteria: { + id: '3f980bbe-7b9b-4fa9-beb1-69d13e94fb0c', + price_range: "1-2" + } }, { id: 'b4adc50d-a584-4820-9140-4d49d7b6c7dc', search_criteria_id: '614af56c-88cb-4ea7-bec5-fbdf9b67c24a', partner_id: '5f80bfefe8d808000ea212c1', + search_criteria: { + id: '614af56c-88cb-4ea7-bec5-fbdf9b67c24a', + price_range: "1000-5000" + } }, ], }, @@ -1451,7 +1458,7 @@ describe("Partner type", () => { partnerAlertsConnection(first: 10) { edges { node { - id + priceRange } } } @@ -1469,12 +1476,12 @@ describe("Partner type", () => { edges: [ { node: { - id: "8754ff90-b020-425b-8dae-894ce5ad9d1f", + priceRange: "1-2", }, }, { node: { - id: "b4adc50d-a584-4820-9140-4d49d7b6c7dc" + priceRange: "1000-5000" } } ], diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index 493640cca7..add6ea53f2 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -46,12 +46,11 @@ import { setVersion } from "schema/v2/image/normalize" import { compact } from "lodash" import { InquiryRequestType } from "./partnerInquiryRequest" import { PartnerDocumentsConnection } from "./partnerDocumentsConnection" -import { AlertsSummaryFields } from "../Alerts" +import { AlertType, AlertsSummaryFields, PartnerAlertsFields } from "../Alerts" import { ArtworkVisibility, ArtworkVisibilityEnumValues, } from "schema/v2/artwork/artworkVisibility" -import { PartnerAlertType } from "./partnerAlerts" const isFairOrganizer = (type) => type === "FairOrganizer" const isGallery = (type) => type === "PartnerGallery" @@ -157,7 +156,8 @@ export const PartnerType = new GraphQLObjectType({ const PartnerAlertsConnectionType = connectionWithCursorInfo({ name: "PartnerAlerts", - nodeType: PartnerAlertType, + edgeFields: PartnerAlertsFields, + nodeType: AlertType, }).connectionType return { @@ -260,6 +260,7 @@ export const PartnerType = new GraphQLObjectType({ _id, gravityArgs ) + const totalCount = parseInt(headers["x-total-count"] || "0", 10) return paginationResolver({ @@ -269,7 +270,7 @@ export const PartnerType = new GraphQLObjectType({ size, body: body.hits, args, - resolveNode: (node) => node, + resolveNode: ({ search_criteria }) => search_criteria, }) }, }, diff --git a/src/schema/v2/partner/partnerAlerts.ts b/src/schema/v2/partner/partnerAlerts.ts deleted file mode 100644 index c417caebb1..0000000000 --- a/src/schema/v2/partner/partnerAlerts.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { pageable } from "relay-cursor-paging" -import { - GraphQLString, - GraphQLObjectType, - GraphQLList, - GraphQLBoolean, -} from "graphql" -import { - connectionWithCursorInfo, - paginationResolver, -} from "schema/v2/fields/pagination" -import { convertConnectionArgsToGravityArgs } from "lib/helpers" -import { CollectorProfileType } from "schema/v2/CollectorProfile/collectorProfile" - -const PartnerCollectorProfilesConnectionType = connectionWithCursorInfo({ - name: "PartnerCollectorProfiles", - nodeType: CollectorProfileType, -}).connectionType - -export const PartnerAlertType = new GraphQLObjectType({ - name: "PartnerAlert", - fields: { - id: { type: GraphQLString }, - searchCriteriaId: { - type: GraphQLString, - resolve: ({ search_criteria_id }) => search_criteria_id, - }, - partnerId: { - type: GraphQLString, - resolve: ({ partner_id }) => partner_id, - }, - score: { type: GraphQLString }, - matchedAt: { - type: GraphQLString, - resolve: ({ matched_at }) => matched_at, - }, - userIds: { - type: new GraphQLList(GraphQLString), - resolve: ({ user_ids }) => user_ids, - }, - artistId: { - type: GraphQLString, - resolve: ({ artist_id }) => artist_id, - }, - collectorProfilesConnection: { - type: PartnerCollectorProfilesConnectionType, - args: pageable({ - totalCount: { - type: GraphQLBoolean, - }, - }), - resolve: async (parent, args, { partnerCollectorProfilesLoader }) => { - if (!partnerCollectorProfilesLoader) return null - - const { page, size, offset } = convertConnectionArgsToGravityArgs(args) - - const { partner_id, user_ids } = parent - if (!partner_id || !user_ids) { - throw new Error( - "partnerId or userIds is undefined in the parent object" - ) - } - - type GravityArgs = { - page: number - size: number - offset: number - total_count: boolean - partner_id: string - user_ids: string[] - } - - const gravityArgs: GravityArgs = { - page, - size, - offset, - total_count: true, - partner_id: parent.partner_id, - user_ids: parent.user_ids, - } - - const { body, headers } = await partnerCollectorProfilesLoader( - gravityArgs - ) - - const collectorProfiles = body.flatMap((item) => - item.collector_profile ? [item.collector_profile].flat() : [] - ) - - const totalCount = parseInt(headers["x-total-count"] || "0", 10) - return paginationResolver({ - totalCount, - offset, - page, - size, - body: collectorProfiles, - args, - }) - }, - }, - }, -}) From 32f6a40153068ced25a87dbbc80732cc0310d1bb Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Wed, 10 Jul 2024 09:13:29 -0400 Subject: [PATCH 11/13] Replace hardcoded ids with IDFields helper on PartnerAlertsType --- _schemaV2.graphql | 7 +++- src/schema/v2/Alerts/index.ts | 65 ++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index 0114cd3443..d0baabd208 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14788,7 +14788,12 @@ type PartnerAlertsEdge { # A cursor for use in pagination cursor: String! - id: String + + # A globally unique ID. + id: ID! + + # A type-specific ID. + internalID: ID! matchedAt: String # The item at the end of the edge diff --git a/src/schema/v2/Alerts/index.ts b/src/schema/v2/Alerts/index.ts index 493cca038d..2bbf661f13 100644 --- a/src/schema/v2/Alerts/index.ts +++ b/src/schema/v2/Alerts/index.ts @@ -12,6 +12,7 @@ import { connectionWithCursorInfo, createPageCursors, emptyConnection, + paginationResolver, } from "schema/v2/fields/pagination" import { ResolverContext } from "types/graphql" import { IDFields } from "../object_identification" @@ -26,6 +27,7 @@ import { pageable } from "relay-cursor-paging" import { convertConnectionArgsToGravityArgs } from "lib/helpers" import { connectionFromArray } from "graphql-relay" import { generateDisplayName } from "../previewSavedSearch/generateDisplayName" +import { CollectorProfileType } from "../CollectorProfile/collectorProfile" type GravityAlertSettingsJSON = { name: string @@ -35,6 +37,11 @@ type GravityAlertSettingsJSON = { frequency: string } +const PartnerCollectorProfilesConnectionType = connectionWithCursorInfo({ + name: "PartnerCollectorProfiles", + nodeType: CollectorProfileType, +}).connectionType + export const AlertSettingsFrequencyType = new GraphQLEnumType({ name: "AlertSettingsFrequency", values: { @@ -486,7 +493,7 @@ export const AlertsSummaryFields = { } export const PartnerAlertsFields = { - id: { type: GraphQLString }, + ...IDFields, searchCriteriaId: { type: GraphQLString, resolve: ({ search_criteria_id }) => search_criteria_id, @@ -512,4 +519,60 @@ export const PartnerAlertsFields = { type: GraphQLString, resolve: ({ artist_id }) => artist_id, }, + collectorProfilesConnection: { + type: PartnerCollectorProfilesConnectionType, + args: pageable({ + totalCount: { + type: GraphQLBoolean, + }, + }), + resolve: async (parent, args, { partnerCollectorProfilesLoader }) => { + if (!partnerCollectorProfilesLoader) return null + + const { page, size, offset } = convertConnectionArgsToGravityArgs(args) + + const { partner_id, user_ids } = parent + if (!partner_id || !user_ids) { + throw new Error( + "partnerId or userIds is undefined in the parent object" + ) + } + + type GravityArgs = { + page: number + size: number + offset: number + total_count: boolean + partner_id: string + user_ids: string[] + } + + const gravityArgs: GravityArgs = { + page, + size, + offset, + total_count: true, + partner_id: parent.partner_id, + user_ids: parent.user_ids, + } + + const { body, headers } = await partnerCollectorProfilesLoader( + gravityArgs + ) + + const collectorProfiles = body.flatMap((item) => + item.collector_profile ? [item.collector_profile].flat() : [] + ) + + const totalCount = parseInt(headers["x-total-count"] || "0", 10) + return paginationResolver({ + totalCount, + offset, + page, + size, + body: collectorProfiles, + args, + }) + }, + }, } From b17b4024934ba372392164f3e971c1a067266a7e Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Wed, 10 Jul 2024 09:17:32 -0400 Subject: [PATCH 12/13] Rename partner.partnerAlertsConnection to partner.alertsConnection --- _schemaV2.graphql | 16 ++++++++-------- src/schema/v2/partner/__tests__/partner.test.js | 9 +++++---- src/schema/v2/partner/partner.ts | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index d0baabd208..4ec4920a19 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14438,6 +14438,14 @@ type PartialArtwork { } type Partner implements Node { + alertsConnection( + after: String + before: String + first: Int + last: Int + page: Int + size: Int + ): PartnerAlertsConnection alertsSummaryArtistsConnection( activeInventory: Boolean after: String @@ -14682,14 +14690,6 @@ type Partner implements Node { ): LocationConnection meta: PartnerMeta name: String - partnerAlertsConnection( - after: String - before: String - first: Int - last: Int - page: Int - size: Int - ): PartnerAlertsConnection partnerPageEligible: Boolean partnerType: String profile: Profile diff --git a/src/schema/v2/partner/__tests__/partner.test.js b/src/schema/v2/partner/__tests__/partner.test.js index f9fc01d4d7..9b58537146 100644 --- a/src/schema/v2/partner/__tests__/partner.test.js +++ b/src/schema/v2/partner/__tests__/partner.test.js @@ -1421,8 +1421,8 @@ describe("Partner type", () => { }) }) - describe("#partnerAlertsConnection", () => { - it("returns partner search criteria details", async () => { + describe("#alertsConnection", () => { + it("returns partner search criteria details and associated search criteria details", async () => { const response = { body: { @@ -1455,7 +1455,7 @@ describe("Partner type", () => { const query = gql` { partner(id: "catty-partner") { - partnerAlertsConnection(first: 10) { + alertsConnection(first: 10) { edges { node { priceRange @@ -1466,13 +1466,14 @@ describe("Partner type", () => { } ` const partnerSearchCriteriaLoader = () => Promise.resolve(response) + const data = await runAuthenticatedQuery(query, { ...context, partnerSearchCriteriaLoader, }) expect(data).toEqual({ partner: { - partnerAlertsConnection: { + alertsConnection: { edges: [ { node: { diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index add6ea53f2..fa9c95115c 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -228,7 +228,7 @@ export const PartnerType = new GraphQLObjectType({ }) }, }, - partnerAlertsConnection: { + alertsConnection: { type: PartnerAlertsConnectionType, args: pageable({ page: { From cbfb612b7181d0ec46cffd66d656c677b86fae96 Mon Sep 17 00:00:00 2001 From: Jackie Potts Date: Wed, 10 Jul 2024 09:32:42 -0400 Subject: [PATCH 13/13] Remove alert from edge fields and just rely on node itself --- _schemaV2.graphql | 1 - src/schema/v2/Alerts/index.ts | 6 +----- src/schema/v2/partner/partner.ts | 8 ++++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/_schemaV2.graphql b/_schemaV2.graphql index 4ec4920a19..d308d4e435 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -14776,7 +14776,6 @@ type PartnerAlertsConnection { # An edge in a connection. type PartnerAlertsEdge { - alert: Alert artistId: String collectorProfilesConnection( after: String diff --git a/src/schema/v2/Alerts/index.ts b/src/schema/v2/Alerts/index.ts index 2bbf661f13..416e4e986d 100644 --- a/src/schema/v2/Alerts/index.ts +++ b/src/schema/v2/Alerts/index.ts @@ -492,7 +492,7 @@ export const AlertsSummaryFields = { }, } -export const PartnerAlertsFields = { +export const PartnerAlertsEdgeFields = { ...IDFields, searchCriteriaId: { type: GraphQLString, @@ -507,10 +507,6 @@ export const PartnerAlertsFields = { type: GraphQLString, resolve: ({ matched_at }) => matched_at, }, - alert: { - type: AlertType, - resolve: ({ search_criteria }) => search_criteria, - }, userIds: { type: new GraphQLList(GraphQLString), resolve: ({ user_ids }) => user_ids, diff --git a/src/schema/v2/partner/partner.ts b/src/schema/v2/partner/partner.ts index fa9c95115c..421ef9632b 100644 --- a/src/schema/v2/partner/partner.ts +++ b/src/schema/v2/partner/partner.ts @@ -46,7 +46,11 @@ import { setVersion } from "schema/v2/image/normalize" import { compact } from "lodash" import { InquiryRequestType } from "./partnerInquiryRequest" import { PartnerDocumentsConnection } from "./partnerDocumentsConnection" -import { AlertType, AlertsSummaryFields, PartnerAlertsFields } from "../Alerts" +import { + AlertType, + AlertsSummaryFields, + PartnerAlertsEdgeFields, +} from "../Alerts" import { ArtworkVisibility, ArtworkVisibilityEnumValues, @@ -156,7 +160,7 @@ export const PartnerType = new GraphQLObjectType({ const PartnerAlertsConnectionType = connectionWithCursorInfo({ name: "PartnerAlerts", - edgeFields: PartnerAlertsFields, + edgeFields: PartnerAlertsEdgeFields, nodeType: AlertType, }).connectionType