How would one execute a graphQL query/mutation with variables? I'm using this client: https://github.com/graphql-dotnet/graphql-client
I'm trying to perform the following:
https://help.shopify.com/en/api/custom-storefronts/storefront-api/guides/updating-customers#creating-the-customer
mutation customerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
}
}
}
Variables:
{
"input": {
"email": "[email protected]",
"password": "HiZqFuDvDdQ7"
}
}
my code:
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 = "[email protected]",
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);
Found the solution. It is supposed to be an anonymous type. Like so:
var v = new { email = "[email protected]", password = "fdsafsdfsdf" };
var request = new GraphQLRequest
{
Query = @"mutation customerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
}
}
}",
Variables = new
{
input = v
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With