Getting results back from Shopify's graphql which it not in a standard structure to be able to deserialize simply.
Here's the result, but note the list of item1
, item2
, etc which can be from 1 to 100 items returned and this is the part I'm not sure how to deserialize and is my main question. Specifically, to a strongly typed List<Item>
collection of items such that I can they query for any UserErrors
, i.e. something like: lstItems.Any(l => l.UserErrors.Any())
.
The second issue is that data
will not always have these contents...other GraphQL queries will have different responses. Perhaps in this case, I should rename data
in the string to another class name that will have these contents, then deserialize?
{
"data":{
"item1":{
"userErrors":[
]
},
"item2":{
"userErrors":[
]
}
},
"extensions":{
...
}
}
Here's what QuickType comes up with, but again, it assumes a discrete list of Items
:
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class InventoryUpdateResult
{
[JsonProperty("data")]
public Data Data { get; set; }
[JsonProperty("extensions")]
public Extensions Extensions { get; set; }
}
public partial class Data
{
[JsonProperty("item1")]
public Item Item1 { get; set; }
[JsonProperty("item2")]
public Item Item2 { get; set; }
}
public partial class Item
{
[JsonProperty("userErrors")]
public UserError[] UserErrors { get; set; }
}
public partial class UserError
{
[JsonProperty("field")]
public string[] Field { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
}
public partial class Extensions
{
....
}
}