/
seller_reject_offer_mutation.ts
57 lines (56 loc) · 1.76 KB
/
seller_reject_offer_mutation.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
48
49
50
51
52
53
54
55
56
57
import { graphql } from "graphql"
import { mutationWithClientMutationId } from "graphql-relay"
import { OrderOrFailureUnionType } from "./types/order_or_error_union"
import { SellerOrderFields } from "./query_helpers"
import gql from "lib/gql"
import { extractEcommerceResponse } from "./extractEcommerceResponse"
import { RejectOfferMutationInputType } from "./types/reject_offer_mutation_input_type"
import { ResolverContext } from "types/graphql"
export const SellerRejectOfferMutation = mutationWithClientMutationId<
any,
any,
ResolverContext
>({
name: "sellerRejectOffer",
description: "Rejects an offer",
inputFields: RejectOfferMutationInputType.getFields(),
outputFields: {
orderOrError: {
type: OrderOrFailureUnionType,
},
},
mutateAndGetPayload: ({ offerId, rejectReason }, context) => {
const { accessToken, exchangeSchema } = context
if (!accessToken) {
return new Error("You need to be signed in to perform this action")
}
const mutation = gql`
mutation sellerRejectOffer($offerId: ID!, $rejectReason: EcommerceCancelReasonTypeEnum!) {
ecommerceSellerRejectOffer(input: {
offerId: $offerId,
rejectReason: $rejectReason,
}) {
orderOrError {
__typename
... on EcommerceOrderWithMutationSuccess {
order {
${SellerOrderFields}
}
}
... on EcommerceOrderWithMutationFailure {
error {
type
code
data
}
}
}
}
}
`
return graphql(exchangeSchema, mutation, null, context, {
offerId,
rejectReason,
}).then(extractEcommerceResponse("ecommerceSellerRejectOffer"))
},
})