flutter Shopify Storefront客户未设置电话号码

bd1hkmkf  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(111)

我正在尝试调用Shopify storefront GraphQL来创建客户。正在成功创建客户。但是,它不设置为突变提供的电话号码。
突变:

const String customerCreateMutation = r''' 
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $password: String!) {
  customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, password: $password}) {
    customer{
      acceptsMarketing
      createdAt
      tags
      displayName
      email
      firstName
      id
      lastName
      phone
   }
  customerUserErrors {
      code
      field
      message
    }
  }
}
''';

Graphql:

final MutationOptions _options = MutationOptions(
      document: gql(customerCreateMutation),
      variables: {
        'firstName': "john",
        'lastName':"doe",
        'email':"[email protected]",
        'password': "password",
        'acceptsMarketing': false,
        'phone': "9876543211", /// tried as "+919876543211" too
      },
    );
final QueryResult result = await _graphQLClient!.mutate(_options);

当我在结果中打印客户时,我得到的是result.data['customerCreate']['customer'],我可能得到的是null。

{__typename: Customer, acceptsMarketing: false, createdAt: 2023-10-19T12:56:35Z, tags: [], displayName: asdasd asdasd, email: [email protected], firstName: asdasd, id: ********, lastName: asdasd, phone: null, lastIncompleteCheckout: null}

在这里,它将电话作为null发送回去。
我也检查了Shopify商店中创建的客户。但它也是空白的。
如何设置客户的电话号码?还有别的办法吗

z9gpfhce

z9gpfhce1#

Shopify店面GraphQL API在customerCreate突变中使用E.164 standard.作为电话号码
这意味着你需要添加[+] [country code] [number],然后它将接受电话号码。
尝试添加+91

+919876543211

我认为你在突变定义中错过了phone变量

// OLD missing phone variable
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $password: String!) {
  customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, password: $password}) {

// ADD phone variable indefinition
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $phone: String, $password: String!) {
                                                                         HERE ^
  customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, phone: $phone, password: $password}) {
                                                                                  HERE ^

如有疑问,请评论。

相关问题