nozzlegear / ShopifySharp

ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
https://nozzlegear.com/shopify-development-handbook
MIT License
733 stars 303 forks source link

Customer is not returned by graphql mutation #1054

Closed anders-christiansen closed 3 months ago

anders-christiansen commented 3 months ago

Im trying to create customers using the GraphQL API.

I have the below code, but somehow the response object is a customer with all properties being null values. The customer is created in Shopify though, so that works. Maybe im making some mistake?

public async Task<Customer> CreateCustomerFromInputModelAsync(Register.InputModel inputModel)
{
    GraphRequest request = new()
    {
        query = $@"
                mutation customerCreate($input: CustomerInput!) {{
                  customerCreate(input: $input) {{
                    customer {{
                      id
                      email
                      firstName
                      lastName
                      phone
                      metafields(first: 10) {{
                        edges {{
                          node {{
                            id
                            key
                            value
                          }}
                        }}
                      }}
                    }}
                    userErrors {{
                      field
                      message
                    }}
                  }}
                }}
            ",
        variables = new
        {
            input = new
            {
                email = inputModel.Email,
                firstName = "testname",
            }
        }
    };

    var service = _graphServiceFactory.Create(_credentials.Shop_Domain, _credentials.Shop_AccessToken);
    var response = await service.SendAsync<Customer>(request);
    return response;
}
clement911 commented 3 months ago

The return type passed to the Send method should not be Customer but CustomerCreatePayload

anders-christiansen commented 3 months ago

@clement911 Thanks a lot.