graphql-dotnet / graphql-client

A GraphQL Client for .NET Standard
MIT License
619 stars 131 forks source link

Problem with GraphQL.Client.Abstractions #383

Open gbicrobert opened 2 years ago

gbicrobert commented 2 years ago

Hi

I have problem with GraphQL.Client.Abstractions. I have portal with graphQL answer from portal to my request looks:

{
    "data": {
        "pages": {
            "single": {
                "title": "Tworzenie backup",
                "id": 5,
                "path": "database/backup"
            }
        }
    }
}

When I use

var answer_request = await graphQLClient.SendMutationAsync<T>(request);

where T is class -> DataPageSearch

public class DataPageSearch
{
    public Pages Pages { get; set; }
}

public class Pages
{
    public Search Single{ get; set; }
}

public class Single
{
    public List<Result> Results { get; set; }
}

public class Result
{
    public string id { get; set; }
    public string path { get; set; }
    public string title { get; set; }
}

it's evrything ok. But when i try use GraphQL.Client.Abstractions and

var answer_request = await graphQLClient.SendMutationAsync(request, () => new {list = new Single()});

always i get null. Where is problem. Thanks.

rose-a commented 2 years ago

You're missing two levels in your anonymous type.

This would work:

var answer_request = await graphQLClient.SendMutationAsync(request, () => new {
    pages = new Pages()
});