Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk update mutation tweaks #4277

Merged
merged 4 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 43 additions & 47 deletions _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Comment on lines +3208 to +3211
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't errors also be here? It is a part of the response and we seem to be using it in the formattedReturn


type BuyersPremium {
# A formatted price with various currency formatting options.
amount(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -11717,11 +11755,6 @@ type PartnerArtworkGrid implements ArtworkContextGrid {
title: String
}

type PartnerArtworksBulkEditErrors {
count: Int
ids: [String]
}

type PartnerCategory {
cached: Int
categoryType: PartnerCategoryType
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,41 @@ import {
} from "lib/gravityErrorHandler"
import { GraphQLObjectType } from "graphql"
import { GraphQLUnionType } from "graphql"
import { isExisty } from "lib/helpers"

interface Input {
id: string
artsyShippingDomestic: boolean | null
artsyShippingInternational: boolean | null
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"
},
Expand All @@ -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: {
Expand All @@ -104,8 +93,8 @@ export const updatePartnerArtworksMutation = mutationWithClientMutationId<
},
},
outputFields: {
partnerArtworksBulkEditOrError: {
type: UpdatePartnerArtworksMutationType,
bulkUpdatePartnerArtworksOrError: {
type: BulkUpdatePartnerArtworksMutationType,
resolve: (result) => result,
},
},
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/schema/v2/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -314,7 +314,7 @@ export default new GraphQLSchema({
updateUserSaleProfile: updateUserSaleProfileMutation,
updateMyUserProfile: UpdateMyUserProfileMutation,
updateNotificationPreferences: updateNotificationPreferencesMutation,
updatePartnerArtworks: updatePartnerArtworksMutation,
bulkUpdatePartnerArtworks: bulkUpdatePartnerArtworksMutation,
deleteMyUserProfileIcon: deleteCollectorProfileIconMutation,
requestPriceEstimate: requestPriceEstimateMutation,
},
Expand Down