我有以下样本变异:
变异{ checkoutCreate(输入:{ lineItems:[{variantId:“Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80”,数量:1}] }){ 查看 { ID …
在查询本身,您需要 声明变量及其类型 。在你的情况下,这可能看起来像
mutation CreateCheckout($lineItems: [LineItem!]!) { checkoutCreate(input: { $lineItems }) { ... FieldsFromTheQuestion }
操作的名称( CreateCheckout )可以是任何对你有意义的东西;它没有在架构中指定。
CreateCheckout
@galkin的答案可能也是相关的:当您提出请求时,您需要传递密钥下的行项目列表 "input" ,匹配查询中的变量名称。该 原始JSON请求 应该看起来像
"input"
{ "query": "mutation CreateCheckout ...", "variables": { "input": [ { "variantId": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80", "quantity" 2 } ] } }
变量是一个对象,一个值。
使用伪代码,你有 variables = lineItems ,但你需要 variables = { lineItems: lineItems }
variables = lineItems
variables = { lineItems: lineItems }
感谢@galkin和@David Maze,我解决了这个问题:
mutation checkoutCreate($input: CheckoutCreateInput!) { checkoutCreate(input: $input) { checkout { id } checkoutUserErrors { code field message } } }
c#代码:
var request = new GraphQLRequest { Query = m_resource.Resource.GetString("CheckoutCreate"), Variables = new { input = new { LineItems = lineItems // List<LineItem> } };