GraphQL创建订单时notifications参数报[OrderCreationNotificationEnum!]类型错误如何解决
问题根因
报错信息已经明确参数类型不匹配:OrderCreateMutationInput输入对象中的notifications字段期望接收类型为 [OrderCreationNotificationEnum!],也就是由OrderCreationNotificationEnum枚举值构成的非空数组,但你当前传入的是多层嵌套的对象结构,完全不符合类型要求。
OrderCreationNotificationEnum的可选值均为字符串格式的枚举项,常见可选值包括EMAIL、SMS等,不需要嵌套对象包裹布尔值。
修正方案
你只需要将notifications字段的取值改为你需要开启的通知类型对应的枚举值数组即可,比如仅开启邮件通知的写法如下:
mutation{ orderCreate(input: { order: { externalIds:[ {key: "VRPOrderId", value: "abc131"} ] firstName: "John" surname: "Doe" phone: "0405123456" billingFirstName: "John" billingSurname: "Doe" billingEmailAddress: "john@email.com" address: { address: "1 Bourke Street" city: "Melbourne" country: { code: "AU" } postcode: "3000" state: { short: "VIC" } } billingAddress:{ address: "1 Bourke Street" city: "Melbourne" country: { code: "AU" } postcode: "3000" state: { short: "VIC" } } termsAndConditionsAccepted: true } lineItems: [ { variantId: "VmFyaWFudC00NzMz" quantity: 1 totalCents: 22500 postageCents: 1000 }, { variantId: "VmFyaWFudC00NzYy" quantity: 1 totalCents: 22500 postageCents: 500 } ] # 修正后的notifications参数,如需开启多个通知,在数组中追加对应枚举值即可 notifications: [EMAIL] }) { order{ id invoices{ edges{ node{ id lineItems{ id quantity } } } } } status } }
如果需要同时开启多种通知方式,直接在数组中追加对应枚举值即可,比如同时开邮件和短信就写notifications: [EMAIL, SMS],枚举值的具体可选范围可以直接在你使用的GraphQL接口的Playground文档中查询到。
内容的提问来源于stack exchange,提问作者Zee
相关产品推荐
相关产品推荐

