Search code examples
c#graphql-dotnet

How to receive a real object in GraphQL dotnet client app?


I run a GraphQL client and send the queries

        var response3 = await client2.SendQueryAsync<ADescriptorResponse2>(request2);
        var response2 = await client2.SendQueryAsync<dynamic>(request2);
        var response1 = await client2.SendQueryAsync<object>(request2);

There is

   public class ADescriptorResponse2
    {
        public ADescriptor aDescriptor { get; set; }
    }
    public class ADescriptor
    {
        public long  Action { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }

But in the 1st case var response3 = await client2.SendQueryAsync(request2); i receive the response3.Data ==null, type ADescriptorResponse2 In other both cases I receive Data correct but it isNewtonsoft.Json.Linq.JObject type. Why I do not receive the Data of ADescriptorResponse2 filled with data? What is incorrect?


Solution

  • This most probably means that the structure of the data is such that it cannot correctly deserialize to type of ADescriptorResponse2.

    You can check the structure of the data which you get from response2 and response1 and see if it is in the shape of ADescriptorResponse2.

    It could be some nested object issue where you need another object on top of ADescriptorResponse2 or something of that nature.