diff --git a/_schemaV2.graphql b/_schemaV2.graphql index e9aed90d93..1fbd5c48ab 100644 --- a/_schemaV2.graphql +++ b/_schemaV2.graphql @@ -3172,6 +3172,44 @@ type BidIncrementsFormatted { # exceed the size of a 32-bit integer, it's encoded as a string. scalar BigInt +type BulkUpdatePartnerArtworksMutationFailure { + mutationError: GravityMutationError +} + +input BulkUpdatePartnerArtworksMutationInput { + # Whether Artsy domestic shipping should be enabled + artsyShippingDomestic: Boolean + + # Whether Artsy international shipping should be enabled + artsyShippingInternational: Boolean + clientMutationId: String + + # ID of the partner + id: String! + + # The partner location ID to assign + location: String +} + +type BulkUpdatePartnerArtworksMutationPayload { + bulkUpdatePartnerArtworksOrError: BulkUpdatePartnerArtworksMutationType + clientMutationId: String +} + +type BulkUpdatePartnerArtworksMutationSuccess { + skippedPartnerArtworks: BulkUpdatePartnerArtworksResponse + updatedPartnerArtworks: BulkUpdatePartnerArtworksResponse +} + +union BulkUpdatePartnerArtworksMutationType = + BulkUpdatePartnerArtworksMutationFailure + | BulkUpdatePartnerArtworksMutationSuccess + +type BulkUpdatePartnerArtworksResponse { + count: Int + ids: [String] +} + type BuyersPremium { # A formatted price with various currency formatting options. amount( @@ -10561,6 +10599,11 @@ type Mutation { adminUpdateFeatureFlag( input: AdminUpdateFeatureFlagInput! ): AdminUpdateFeatureFlagPayload + + # Update all artworks that belong to the partner + bulkUpdatePartnerArtworks( + input: BulkUpdatePartnerArtworksMutationInput! + ): BulkUpdatePartnerArtworksMutationPayload captureHold(input: CaptureHoldInput!): CaptureHoldPayload commerceAddInitialOfferToOrder( # Parameters for AddInitialOfferToOrder @@ -10905,11 +10948,6 @@ type Mutation { updateNotificationPreferences( input: updateNotificationPreferencesMutationInput! ): updateNotificationPreferencesMutationPayload - - # Update all artworks that belong to the partner - updatePartnerArtworks( - input: UpdatePartnerArtworksMutationInput! - ): UpdatePartnerArtworksMutationPayload updateSavedSearch(input: UpdateSavedSearchInput!): UpdateSavedSearchPayload updateSmsSecondFactor( input: UpdateSmsSecondFactorInput! @@ -11717,11 +11755,6 @@ type PartnerArtworkGrid implements ArtworkContextGrid { title: String } -type PartnerArtworksBulkEditErrors { - count: Int - ids: [String] -} - type PartnerCategory { cached: Int categoryType: PartnerCategoryType @@ -15483,43 +15516,6 @@ type updateNotificationPreferencesMutationPayload { ): [NotificationPreference!]! } -type UpdatePartnerArtworksMutationFailure { - mutationError: GravityMutationError -} - -input UpdatePartnerArtworksMutationInput { - # Whether Artsy domestic shipping should be enabled - artsyShippingDomestic: Boolean - - # Whether Artsy international shipping should be enabled - artsyShippingInternational: Boolean - clientMutationId: String - - # ID of the partner - id: String! - - # The partner location ID to assign - location: String -} - -type UpdatePartnerArtworksMutationPayload { - clientMutationId: String - partnerArtworksBulkEditOrError: UpdatePartnerArtworksMutationType -} - -type UpdatePartnerArtworksMutationSuccess { - partnerArtworksBulkEdit: UpdatePartnerArtworksMutationSuccessDetails -} - -type UpdatePartnerArtworksMutationSuccessDetails { - errors: PartnerArtworksBulkEditErrors - success: Int -} - -union UpdatePartnerArtworksMutationType = - UpdatePartnerArtworksMutationFailure - | UpdatePartnerArtworksMutationSuccess - # Autogenerated input type of UpdateSavedSearch input UpdateSavedSearchInput { attributes: SearchCriteriaAttributes diff --git a/src/schema/v2/partnerArtworksMutation.ts b/src/schema/v2/bulkUpdatePartnerArtworksMutation.ts similarity index 59% rename from src/schema/v2/partnerArtworksMutation.ts rename to src/schema/v2/bulkUpdatePartnerArtworksMutation.ts index 57d29654a4..31f82abad2 100644 --- a/src/schema/v2/partnerArtworksMutation.ts +++ b/src/schema/v2/bulkUpdatePartnerArtworksMutation.ts @@ -13,7 +13,7 @@ import { } from "lib/gravityErrorHandler" import { GraphQLObjectType } from "graphql" import { GraphQLUnionType } from "graphql" -import { isExisty } from "lib/helpers" + interface Input { id: string artsyShippingDomestic: boolean | null @@ -21,44 +21,33 @@ interface Input { location: string | null } -const UpdatePartnerArtworksMutationSuccessDetails = new GraphQLObjectType< +const BulkUpdatePartnerArtworksResponseType = new GraphQLObjectType< any, ResolverContext >({ - name: "UpdatePartnerArtworksMutationSuccessDetails", - fields: () => ({ - success: { type: GraphQLInt }, - errors: { - type: new GraphQLObjectType({ - name: "PartnerArtworksBulkEditErrors", - fields: { - count: { type: GraphQLInt }, - ids: { type: GraphQLList(GraphQLString) }, - }, - }), - }, - }), + name: "BulkUpdatePartnerArtworksResponse", + fields: { + count: { type: GraphQLInt }, + ids: { type: GraphQLList(GraphQLString) }, + }, }) -const UpdatePartnerArtworksMutationSuccessType = new GraphQLObjectType< +const BulkUpdatePartnerArtworksMutationSuccessType = new GraphQLObjectType< any, ResolverContext >({ - name: "UpdatePartnerArtworksMutationSuccess", - isTypeOf: (data) => isExisty(data.success), + name: "BulkUpdatePartnerArtworksMutationSuccess", fields: () => ({ - partnerArtworksBulkEdit: { - type: UpdatePartnerArtworksMutationSuccessDetails, - resolve: (partnerArtworksBulkEdit) => partnerArtworksBulkEdit, - }, + updatedPartnerArtworks: { type: BulkUpdatePartnerArtworksResponseType }, + skippedPartnerArtworks: { type: BulkUpdatePartnerArtworksResponseType }, }), }) -const UpdatePartnerArtworksMutationFailureType = new GraphQLObjectType< +const BulkUpdatePartnerArtworksMutationFailureType = new GraphQLObjectType< any, ResolverContext >({ - name: "UpdatePartnerArtworksMutationFailure", + name: "BulkUpdatePartnerArtworksMutationFailure", isTypeOf: (data) => { return data._type === "GravityMutationError" }, @@ -70,20 +59,20 @@ const UpdatePartnerArtworksMutationFailureType = new GraphQLObjectType< }), }) -const UpdatePartnerArtworksMutationType = new GraphQLUnionType({ - name: "UpdatePartnerArtworksMutationType", +const BulkUpdatePartnerArtworksMutationType = new GraphQLUnionType({ + name: "BulkUpdatePartnerArtworksMutationType", types: [ - UpdatePartnerArtworksMutationSuccessType, - UpdatePartnerArtworksMutationFailureType, + BulkUpdatePartnerArtworksMutationSuccessType, + BulkUpdatePartnerArtworksMutationFailureType, ], }) -export const updatePartnerArtworksMutation = mutationWithClientMutationId< +export const bulkUpdatePartnerArtworksMutation = mutationWithClientMutationId< Input, any, ResolverContext >({ - name: "UpdatePartnerArtworksMutation", + name: "BulkUpdatePartnerArtworksMutation", description: "Update all artworks that belong to the partner", inputFields: { id: { @@ -104,8 +93,8 @@ export const updatePartnerArtworksMutation = mutationWithClientMutationId< }, }, outputFields: { - partnerArtworksBulkEditOrError: { - type: UpdatePartnerArtworksMutationType, + bulkUpdatePartnerArtworksOrError: { + type: BulkUpdatePartnerArtworksMutationType, resolve: (result) => result, }, }, @@ -124,7 +113,22 @@ export const updatePartnerArtworksMutation = mutationWithClientMutationId< } try { - return await updatePartnerArtworksLoader(id, gravityOptions) + const gravityResponse = await updatePartnerArtworksLoader( + id, + gravityOptions + ) + + // In the future it could be helpful to have a list of successfully opted in ids, can add this to gravity at a later date + + const formattedReturn = { + updatedPartnerArtworks: { count: gravityResponse.success, ids: [] }, + skippedPartnerArtworks: { + count: gravityResponse.error.count, + ids: gravityResponse.error.ids, + }, + } + + return formattedReturn } catch (error) { const formattedErr = formatGravityError(error) if (formattedErr) { diff --git a/src/schema/v2/schema.ts b/src/schema/v2/schema.ts index cd2ef3c0a9..ebef68c31e 100644 --- a/src/schema/v2/schema.ts +++ b/src/schema/v2/schema.ts @@ -147,7 +147,7 @@ import { toggleFeatureFlagMutation } from "./admin/mutations/toggleFeatureFlagMu import { MatchConnection } from "./Match" import { PartnerArtistDocumentsConnection } from "./partnerArtistDocumentsConnection" import { PartnerShowDocumentsConnection } from "./partnerShowDocumentsConnection" -import { updatePartnerArtworksMutation } from "./partnerArtworksMutation" +import { bulkUpdatePartnerArtworksMutation } from "./bulkUpdatePartnerArtworksMutation" const PrincipalFieldDirective = new GraphQLDirective({ name: "principalField", @@ -314,7 +314,7 @@ export default new GraphQLSchema({ updateUserSaleProfile: updateUserSaleProfileMutation, updateMyUserProfile: UpdateMyUserProfileMutation, updateNotificationPreferences: updateNotificationPreferencesMutation, - updatePartnerArtworks: updatePartnerArtworksMutation, + bulkUpdatePartnerArtworks: bulkUpdatePartnerArtworksMutation, deleteMyUserProfileIcon: deleteCollectorProfileIconMutation, requestPriceEstimate: requestPriceEstimateMutation, },