GraphQL dotnet Client response not deserializing

665 views Asked by At

When deserializing into a dynamic I can get a response but when I try to deserialize into a typed object I get nothing back.

Types being serialized

public class User {
        public string Forename { get; set; }
    }

public class UserCollectionResponseType {
    public List<User> Items { get; set; }
}

Request being made:

var response = await graphQLHttpClient.SendQueryAsync<UserCollectionResponseType >(this.request).ConfigureAwait(false);

Sample response from API

{
  "data": {
    "users": {
      "items": [
        {
          "forename": "4212hotp0i"
        },
        {
          "forename": "XO - Test"
        },
        {
          "forename": "5422q5htsd"
        },
        {
          "forename": "XR - Test"
        },
        {
          "forename": "2035snyyex"
        },
        {
          "forename": "2379plsmri"
        },
        {
          "forename": "7100e1igjl"
        },
        {
          "forename": "94 - Test"
        },
        {
          "forename": "ZX - Test"
        },
        {
          "forename": "Test"
        }
      ]
    }
  }
}
1

There are 1 answers

1
jjnrmason On

I was missing the Data part of the Json when trying to deserialize into an object.

My final objects looked like this:

public partial class Data {
    [JsonProperty("users")]
    public Users Users { get; set; }
}

public partial class Users {
    [JsonProperty("items")]
    public Item[] Items { get; set; }
}

public partial class Item {
    [JsonProperty("forename")]
    public string Forename { get; set; }
}