/
stitching.ts
926 lines (865 loc) · 29.5 KB
/
stitching.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
import { GraphQLError, GraphQLSchema, Kind, SelectionSetNode } from "graphql"
import { amountSDL, amount } from "schema/v2/fields/money"
import gql from "lib/gql"
import { toGlobalId } from "graphql-relay"
import { delegateToSchema } from "@graphql-tools/delegate"
import { ArtworkVersionType } from "schema/v2/artwork_version"
import { WrapQuery } from "graphql-tools"
const orderTotals = [
"itemsTotal",
"sellerTotal",
"commissionFee",
"totalListPrice",
"buyerTotal",
"taxTotal",
"shippingTotal",
"transactionFee",
"artsyTotal",
]
const orderTotalsSDL = orderTotals.map(amountSDL)
const lineItemTotals = ["shippingTotal", "listPrice", "commissionFee"]
const lineItemTotalsSDL = lineItemTotals.map(amountSDL)
const offerAmountFields = ["amount", "taxTotal", "shippingTotal", "buyerTotal"]
const offerAmountFieldsSDL = offerAmountFields.map(amountSDL)
const shippingQuoteFields = ["price"]
const shippingQuoteFieldsSDL = shippingQuoteFields.map(amountSDL)
export const exchangeStitchingEnvironment = ({
localSchema,
exchangeSchema,
}: {
localSchema: GraphQLSchema
exchangeSchema: GraphQLSchema & { transforms: any }
}) => {
type DetailsFactoryInput = { from: string; to: string }
/**
* This returns a resolver which can take an exchange OrderParty union
* and convert it into a metaphysics `OrderParty`.
*
* You pass in the field to get the details from, and and the new fieldName
*/
const partyUnionToDetailsFactory = ({ from, to }: DetailsFactoryInput) => {
// We abuse the query alias feature to make sure that all
// the data we need to generate the full object from
// is included.
//
// It's possible that this working around a bug in how the fragment is put
// together by graphql-tools.
const aliasedPartyFragment = (field, alias) => {
return gql`
... on CommerceOrder {
${alias}: ${field} {
__typename
... on CommerceUser {
__typename
id
}
... on CommercePartner {
__typename
id
}
}
}`
}
return {
// Bit of a magic in next line, when adding fragment, it seems
// all second level fields (e.g. b in this query { a { b } }) are
// ignored, so __typename and id couldn't be added, so the hack
// was to alias the fragment field and that gets the current fields
fragment: aliasedPartyFragment(from, to),
resolve: (parent, _args, context, info) => {
const typename = parent[to].__typename
const id = parent[to].id
// Make a call to the user or partner resolver on query to
// grab our Metaphysics representations
return (
info.mergeInfo
.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: typename === "CommerceUser" ? "user" : "partner",
args: {
id,
},
context,
info,
transforms: exchangeSchema.transforms,
})
// Re-jigger the type systems back into place, as right now
// it is considered a CommerceUser and clients will reject it.
.then((response) => {
response.__typename =
typename === "CommerceUser" ? "User" : "Partner"
return response
})
)
},
}
}
const buyerDetailsResolver = partyUnionToDetailsFactory({
from: "buyer",
to: "buyerDetails",
})
const sellerDetailsResolver = partyUnionToDetailsFactory({
from: "seller",
to: "sellerDetails",
})
const fromDetailsResolver = partyUnionToDetailsFactory({
from: "from",
to: "fromDetails",
})
const creditCardResolver = {
fragment: `fragment CommerceOrderCreditCard on CommerceOrder { creditCardId }`,
resolve: (parent, _args, context, info) => {
const id = parent.creditCardId
if (!id) {
return null
} else {
return info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "creditCard",
args: {
id,
},
context,
info,
transforms: exchangeSchema.transforms,
})
}
},
}
const paymentMethodDetailsResolver = {
fragment: gql`
fragment CommerceOrderPaymentMethod on CommerceOrder {
creditCardId
bankAccountId
paymentMethod
}
`,
resolve: async (parent, _args, context, info) => {
const { creditCardId, bankAccountId, paymentMethod } = parent
if (paymentMethod === "CREDIT_CARD" && Boolean(creditCardId)) {
const creditCard = await info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "creditCard",
args: {
id: creditCardId,
},
context,
info,
})
return creditCard
} else if (
(paymentMethod === "US_BANK_ACCOUNT" ||
paymentMethod === "SEPA_DEBIT") &&
Boolean(bankAccountId)
) {
const bankAccount = await info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "bankAccount",
args: {
id: bankAccountId,
},
context,
info,
})
return bankAccount
} else if (paymentMethod === "WIRE_TRANSFER") {
return { __typename: "WireTransfer", isManualPayment: true }
} else {
return null
}
},
}
const inquiryOrderResolvers = {
isInquiryOrder: {
fragment: gql`
fragment CommerceOrderIsInquiryOrder on CommerceOfferOrder {
impulseConversationId
}
`,
resolve: async (order) => {
const { impulseConversationId } = order
return Boolean(impulseConversationId)
},
},
conversation: {
fragment: gql`
fragment CommerceOrderConversation on CommerceOfferOrder {
impulseConversationId
}
`,
resolve: async (order, _args, context, info) => {
const { impulseConversationId } = order
if (!impulseConversationId) return null
return info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "_do_not_use_conversation",
args: { id: impulseConversationId },
context,
info,
})
},
},
}
// Map the totals array to a set of resolvers that call the amount function
// the type param is only used for the fragment name
const totalsResolvers = (type, totalSDLS) =>
reduceToResolvers(
totalSDLS.map((name) => ({
[name]: {
fragment: `fragment ${type}_${name} on ${type} { ${name}Cents currencyCode }`,
resolve: (parent, args, _context, _info) => {
return amount((_) => parent[name + "Cents"]).resolve(parent, args)
},
},
}))
)
const buyerProfileResolver = {
fragment: gql`
... on CommerceOrder {
buyer {
... on CommerceUser {
id
}
}
}
`,
resolve: async (parent, _args, context, info) => {
return await info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "collectorProfile",
args: { userID: parent.buyer.id },
context,
info,
})
},
}
// Used to convert an array of `key: resolvers` to a single obj
const reduceToResolvers = (arr) => arr.reduce((a, b) => ({ ...a, ...b }))
return {
// The SDL used to declare how to stitch an object
extensionSchema: gql`
extend type Conversation {
orderConnection(
sellerId: ID
participantType: CommerceOrderParticipantEnum
state: CommerceOrderStateEnum
states: [CommerceOrderStateEnum!]
after: String
before: String
first: Int
last: Int
): CommerceOrderConnectionWithTotalCount
}
extend type CommerceShippingQuote {
${shippingQuoteFieldsSDL.join("\n")}
}
extend type CommerceLineItem {
artwork: Artwork
artworkVersion: ArtworkVersion
artworkOrEditionSet: ArtworkOrEditionSetType
${lineItemTotalsSDL.join("\n")}
}
extend type CommerceBuyOrder {
buyerDetails: OrderParty
buyerProfile: CollectorProfileType
sellerDetails: OrderParty
creditCard: CreditCard
paymentMethodDetails: PaymentMethodUnion
conversation: Conversation
${orderTotalsSDL.join("\n")}
}
extend type CommerceOfferOrder {
buyerDetails: OrderParty
buyerProfile: CollectorProfileType
sellerDetails: OrderParty
creditCard: CreditCard
paymentMethodDetails: PaymentMethodUnion
isInquiryOrder: Boolean!
conversation: Conversation
${orderTotalsSDL.join("\n")}
${amountSDL("offerTotal")}
}
extend interface CommerceOrder {
buyerDetails: OrderParty
buyerProfile: CollectorProfileType
sellerDetails: OrderParty
creditCard: CreditCard
paymentMethodDetails: PaymentMethodUnion
${orderTotalsSDL.join("\n")}
}
extend type CommerceOffer {
fromDetails: OrderParty
${offerAmountFieldsSDL.join("\n")}
}
extend type Me {
orders(first: Int, last: Int, after: String, before: String, mode: CommerceOrderModeEnum, sellerId: String, sort: CommerceOrderConnectionSortEnum, states: [CommerceOrderStateEnum!]): CommerceOrderConnectionWithTotalCount
}
extend type CollectorResume {
buyerActivity: CommerceBuyerActivity
}
extend type Mutation {
# Creates an order and links the conversation to it
createInquiryOrder(
input: CommerceCreateInquiryOrderWithArtworkInput!
): CommerceCreateInquiryOrderWithArtworkPayload
createInquiryOfferOrder(
input: CommerceCreateInquiryOfferOrderWithArtworkInput!
): CommerceCreateInquiryOfferOrderWithArtworkPayload
# Submits an OfferOrder and creates a conversation for it
submitOfferOrderWithConversation(
input: CommerceSubmitOrderWithOfferInput!
): CommerceSubmitOrderWithOfferPayload
}
`,
// Resolvers for the above
resolvers: {
CollectorResume: {
buyerActivity: {
fragment: gql`
... on CollectorResume {
userId
purchases {
totalAuctionCount
totalPrivateSaleCount
}
}
`,
resolve: async (parent, _args, context, info) => {
const nonBnmoPurchases =
(parent?.purchases?.totalAuctionCount ?? 0) +
(parent?.purchases?.totalPrivateSaleCount ?? 0)
try {
const exchangeArgs = {
buyerId: parent.userId,
}
const bnmoPurchases = await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "query",
fieldName: "commerceBuyerActivity",
args: exchangeArgs,
context,
info,
})
return {
totalPurchases: bnmoPurchases.totalPurchases + nonBnmoPurchases,
}
} catch (error) {
console.error(
"[schema/v2/conversation/collectorResume/totalPurchases] Error:",
error
)
return {
totalPurchases: nonBnmoPurchases,
}
}
},
},
},
Conversation: {
orderConnection: {
fragment: gql`
fragment Conversation_orderConnection on Conversation {
internalID
}
`,
resolve: (
{ internalID: conversationId },
{
sellerId,
...requestArgs
}: {
/* Deprecated - use sellerId */
participantType?: any
/* Overrides buyer_id in request */
sellerId?: string
first?: number
last?: number
after?: string
before?: string
state?: string
states?: [string]
},
context,
info
) => {
const viewerKey = sellerId
? { sellerId: sellerId }
: { buyerId: context.userID }
const exchangeArgs = {
...requestArgs,
...viewerKey,
impulseConversationId: conversationId,
}
return info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "query",
fieldName: "commerceOrders",
args: exchangeArgs,
context,
info,
})
},
},
},
CommerceShippingQuote: {
...totalsResolvers("CommerceShippingQuote", shippingQuoteFields),
},
CommerceBuyOrder: {
// The money helper resolvers
...totalsResolvers("CommerceBuyOrder", orderTotals),
buyerDetails: buyerDetailsResolver,
buyerProfile: buyerProfileResolver,
sellerDetails: sellerDetailsResolver,
creditCard: creditCardResolver,
paymentMethodDetails: paymentMethodDetailsResolver,
},
CommerceOfferOrder: {
...totalsResolvers("CommerceOfferOrder", orderTotals),
buyerDetails: buyerDetailsResolver,
buyerProfile: buyerProfileResolver,
sellerDetails: sellerDetailsResolver,
creditCard: creditCardResolver,
paymentMethodDetails: paymentMethodDetailsResolver,
...inquiryOrderResolvers,
},
CommerceLineItem: {
artwork: {
fragment: `fragment CommerceLineItemArtwork on CommerceLineItem { artworkId }`,
resolve: (parent, _args, context, info) => {
const id = parent.artworkId
return info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "artwork",
args: {
id,
},
context,
info,
})
},
},
artworkVersion: {
fragment: `fragment CommerceLineItemArtwork on CommerceLineItem { artworkVersionId }`,
resolve: (parent, _args, context, info) => {
const id = parent.artworkVersionId
const globalID = toGlobalId("ArtworkVersion", id)
return delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "node",
args: {
id: globalID,
},
context,
info,
transforms: exchangeSchema.transforms,
returnType: ArtworkVersionType,
})
},
},
artworkOrEditionSet: {
fragment: gql`
... on CommerceLineItem {
artworkId
editionSetId
}
`,
resolve: async (parent, _args, context, info) => {
const artworkId = parent.artworkId
const editionSetId = parent.editionSetId
if (editionSetId) {
return info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "artwork",
args: {
id: artworkId,
},
context,
info,
transforms: [
// Wrap document takes a subtree as an AST node
new WrapQuery(
// path at which to apply wrapping and extracting
["artwork"],
(subtree: SelectionSetNode) => ({
// we create a wrapping AST Field
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "editionSet",
},
arguments: [
{
kind: Kind.ARGUMENT,
name: {
kind: Kind.NAME,
value: "id",
},
value: {
kind: Kind.STRING,
value: editionSetId,
},
},
],
// Inside the field selection
selectionSet: subtree,
}),
// how to process the data result at path
(result) => {
return result.editionSet
}
),
],
})
}
return info.mergeInfo.delegateToSchema({
schema: localSchema,
operation: "query",
fieldName: "artwork",
args: {
id: artworkId,
},
context,
info,
})
},
},
...totalsResolvers("CommerceLineItem", lineItemTotals),
},
CommerceOrder: {
// The money helper resolvers
...totalsResolvers("CommerceOrder", orderTotals),
buyerDetails: buyerDetailsResolver,
sellerDetails: sellerDetailsResolver,
creditCard: creditCardResolver,
paymentMethodDetails: paymentMethodDetailsResolver,
},
CommerceOffer: {
...totalsResolvers("CommerceOffer", offerAmountFields),
fromDetails: fromDetailsResolver,
},
Me: {
orders: {
fragment: gql`... on Me {
__typename
}`,
resolve: async (_source, args, context, info) => {
return await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "query",
fieldName: "commerceMyOrders",
args,
context,
info,
})
},
},
},
Mutation: {
createInquiryOrder: {
resolve: async (_source, args, context, info) => {
const {
conversationLoader,
conversationCreateConversationOrderLoader,
} = context
const {
input: { impulseConversationId },
} = args
try {
await conversationLoader(impulseConversationId)
} catch (e) {
console.log("error", e)
throw new GraphQLError(
`[metaphysics @ exchange/v2/stitching] Conversation not found`
)
}
const orderResult = await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "mutation",
fieldName: "commerceCreateInquiryOrderWithArtwork",
args,
context,
info,
transforms: [
// add orderOrError.order.internalID to the Order selectionSet
new WrapQuery(
[
"commerceCreateInquiryOrderWithArtwork",
"orderOrError",
"order",
],
(selectionSet: SelectionSetNode) => {
const newSelections = [
...selectionSet.selections,
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "internalID",
},
},
]
return { ...selectionSet, selections: newSelections }
},
(result) => {
return result
}
),
],
})
const { orderOrError } = orderResult
if (orderOrError.error) {
return orderResult
} else if (orderOrError.order) {
const {
order: { internalID: orderId },
} = orderOrError
try {
await conversationCreateConversationOrderLoader({
conversation_id: impulseConversationId,
exchange_order_id: orderId,
})
} catch (e) {
throw new GraphQLError(
"[metaphysics @ exchange/v2/stitching] Impulse: request to associate order with conversation failed"
)
}
}
return orderResult
},
},
createInquiryOfferOrder: {
resolve: async (_source, args, context, info) => {
const {
conversationLoader,
conversationCreateConversationOrderLoader,
} = context
const {
input: { impulseConversationId },
} = args
try {
await conversationLoader(impulseConversationId)
} catch (e) {
throw new GraphQLError(
`[metaphysics @ exchange/v2/stitching] Conversation not found`
)
}
const offerResult = await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "mutation",
fieldName: "commerceCreateInquiryOfferOrderWithArtwork",
args,
context,
info,
transforms: [
// add orderOrError.order.internalID to the Order selectionSet
new WrapQuery(
[
"commerceCreateInquiryOfferOrderWithArtwork",
"orderOrError",
"order",
],
(selectionSet: SelectionSetNode) => {
const newSelections = [
...selectionSet.selections,
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "internalID",
},
},
]
return { ...selectionSet, selections: newSelections }
},
(result) => {
return result
}
),
],
})
const { orderOrError } = offerResult
if (orderOrError.error) {
// if we got an error from exchange, return it immediately
return offerResult
} else if (orderOrError.order) {
// attempt to associate the order with the conversation
const {
order: { internalID: orderId },
} = orderOrError
try {
await conversationCreateConversationOrderLoader({
conversation_id: impulseConversationId,
exchange_order_id: orderId,
})
} catch (e) {
throw new GraphQLError(
"[metaphysics @ exchange/v2/stitching] Impulse: request to associate offer with conversation failed"
)
}
}
return offerResult
},
},
submitOfferOrderWithConversation: {
resolve: async (_source, args, context, info) => {
const { submitArtworkInquiryRequestLoader } = context
const submitOrderWithOffer = await info.mergeInfo.delegateToSchema({
schema: exchangeSchema,
operation: "mutation",
fieldName: "commerceSubmitOrderWithOffer",
args,
context,
info,
transforms: [
// add orderOrError.order.internalID, orderOrError.order.lastOffer.note, orderOrError.order.lineItems.edges[0].node.artworkId
// to the Order selectionSet
new WrapQuery(
["commerceSubmitOrderWithOffer", "orderOrError", "order"],
(selectionSet: SelectionSetNode) => {
const newSelections = [
...selectionSet.selections,
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "internalID",
},
},
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "source",
},
},
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "paymentMethod",
},
},
{
kind: Kind.INLINE_FRAGMENT,
typeCondition: {
kind: Kind.NAMED_TYPE,
name: {
kind: Kind.NAME,
value: "CommerceOfferOrder",
},
},
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "myLastOffer",
},
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "note",
},
},
],
},
},
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "lineItems",
},
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "edges",
},
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "node",
},
selectionSet: {
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: "artworkId",
},
},
],
},
},
],
},
},
],
},
},
],
},
},
]
return { ...selectionSet, selections: newSelections }
},
(result) => {
return result
}
),
],
})
const { orderOrError } = submitOrderWithOffer
if (
orderOrError.error ||
!orderOrError.order ||
orderOrError.order.source === "inquiry" ||
orderOrError.order.state === "IN_REVIEW"
) {
return submitOrderWithOffer
}
try {
const { order } = orderOrError
await submitArtworkInquiryRequestLoader({
artwork: order.lineItems.edges[0].node.artworkId,
message: order.myLastOffer.note,
order_id: order.internalID,
})
} catch (e) {
console.error(e)
throw new GraphQLError(
`[metaphysics @ exchange/v2/stitching] Gravity: request to create inquiry failed`
)
}
return submitOrderWithOffer
},
},
},
},
}
}