graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Why I do not receive a real object?

Open ZedZipDev opened this issue 4 years ago • 6 comments
trafficstars

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<ADescriptorResponse2>(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?

ZedZipDev avatar Aug 08 '21 13:08 ZedZipDev

Please post your query string... I suspect you're missing the root data object...

rose-a avatar Sep 16 '21 21:09 rose-a

I'm having the same problem here. What do you mean by root data object in the query string @rose-a?

ErlendFax avatar Apr 01 '22 12:04 ErlendFax

The client deserializes the data field in the GraphQL response, not the first element mentioned in the query... a common mistake to make is to forget to wrap the desired object in an object containing an accordingly named field of that type (the ResponseType in the Readme example).

rose-a avatar Apr 03 '22 07:04 rose-a

@rose-a have a similar problem here, if I understand ok, does the client expects a root element "data" from the graphql response from the server?

No matter if I use dynamic object or a object that matches the response, the response.data is always null here, any idea?

image

public class ApiResult { public string ClientIP { get; set; } public string ExecutionTime { get; set; } public string ServerName { get; set; } public AgentApiResult Result { get; set; } public string StatusCode { get; set; } }

public class AgentApiResult
{
    public List<AgentPolicy> agentPolicies { get; set; }
}

public class AgentPolicy
{
    public int builderId { get; set; }
    public string type { get; set; }
    public string level { get; set; }
    public List<Market> markets { get; set; }

    public List<Division> divisions { get; set; }

    public class Market
    {
        public int id { get; set; }
        public string name { get; set; }
    }

    public class Division
    {
        public int builderId { get; set; }
        public string builderName { get; set; }
    }
}

Response looks like this

{ "StatusCode": "Success", "ServerName": "NHSDEVAPI1", "ClientIP": "172.16.2.251", "ExecutionTime": "00:00:00.3523738", "Result": { "agentPolicies": [ { "builderId": 34, "type": "CoOpConfirmation", "level": "Market", "divisions": [ { "builderId": 38 }, { "builderId": 394 }, { "builderId": 396 }, ], "markets": [ { "id": 18 }, { "id": 19 }, { "id": 21 }, ] } ] } }

arekucr avatar Jun 29 '22 00:06 arekucr

What if the graphql server defined a different format for the response that this case were in our API

image

arekucr avatar Jun 29 '22 01:06 arekucr

So this server is not compatible with GraphQL official specification.

sungam3r avatar Jun 30 '22 16:06 sungam3r