Closed YaroslavKormushyn closed 1 year ago
If you have a complex object, it must be serialized to send a request. If you create it inside the "graphql lambda" ZeroQL doesn't have access to it and can't serialize it before the request. It is a limitation of the current approach.
To make it work you must create an instance before the request and pass it as a variable. Like that:
var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:10000/graphql");
var client = new TestServerGraphQLClient(httpClient);
var variables = new { Filter = new ItemFilter { PageFilter = new PageFilter { Page = 0 } } };
var response = await client.Query(variables, static (i, q) =>
q.GetItemsPaged(
filter: i.Filter,
selector: page => new
{
page.Number,
page.TotalPages,
Items = page.Content(b => new { Id = b.Id, Name = b.Name, Comment = b.Comment }),
})));
Thanks for the clarification! I have seen this in the example, but the variable has been really simple, so I thought it's something else. I have updated the code and it compiles fine now.
Describe the bug If a query has a complex-type variable as a filter, any initialization of the variable will fail with a compiler-time error:
FailedToConvertPartOfTheQuery Failed to convert to graphql query
.How to Reproduce We have a complex schema like this (cut for brevity):
Then with the generated client code, the next query won't compile:
Expected behavior The query should compile and the filter variable should be correctly added in the GraphQL query.
Screenshots
Environment (please complete the following information):