首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在进行GraphQL查询/突变时,变量应该是什么数据类型?

在进行GraphQL查询/突变时,变量应该是什么数据类型?
EN

Stack Overflow用户
提问于 2019-02-20 04:36:26
回答 1查看 2.9K关注 0票数 2

如何使用变量执行graphQL查询/突变?我正在使用这个客户端:https://github.com/graphql-dotnet/graphql-client

我正在尝试执行以下操作:

https://help.shopify.com/en/api/custom-storefronts/storefront-api/guides/updating-customers#creating-the-customer

代码语言:javascript
复制
mutation customerCreate($input: CustomerCreateInput!) {
      customerCreate(input: $input) {
        userErrors {
          field
          message
        }
        customer {
          id
        }
      }
    }

变量:

代码语言:javascript
复制
{
  "input": {
    "email": "user@example.com",
    "password": "HiZqFuDvDdQ7"
  }
}

我的代码:

代码语言:javascript
复制
    var request = new GraphQLRequest();
    request.Query = @"mutation customerCreate($input: CustomerCreateInput!) {
          customerCreate(input: $input) {
            userErrors {
              field
              message
            }
            customer {
              id
            }
          }
        }";

    request.OperationName = "customerCreate";
    request.Variables = new
    {
        email = "user@example.com",
        password = "HiZqFuDvDdQ7"
    };

    var client = new GraphQLClient("https://kitkatco.myshopify.com/api/graphql");
    client.DefaultRequestHeaders.Add("X-Shopify-Storefront-Access-Token", new List<string> { "d021132503b1357116d5f1e51abd9f39" });
    var response = await client.PostAsync(request);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-20 05:12:06

找到了解决方案。它应该是匿名类型。如下所示:

代码语言:javascript
复制
    var v = new { email = "test1@yahoo.com", password = "fdsafsdfsdf" };
    var request = new GraphQLRequest
    {
        Query = @"mutation customerCreate($input: CustomerCreateInput!) {
          customerCreate(input: $input) {
            userErrors {
              field
              message
            }
            customer {
              id
            }
          }
        }",
        Variables = new
        {
            input = v
        }

    };
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54774521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档