ZeroQL icon indicating copy to clipboard operation
ZeroQL copied to clipboard

Ability to get field optionally

Open N0D4N opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. I want to be able to request a field or not request it based on data in runtime. Imagine scenario, user has a set of settings, and if some of them are turned off there is no need to fetch certain data from GraphQL API, of course one single field may not matter but if there a couple of them it may start to add up, especially if field is complex type. To visualise consider currently not working snippet of code

using var http = new HttpClient()
{
	BaseAddress = new Uri("https://swapi-graphql.netlify.app/.netlify/functions/index")
};
using var client = new ZeroQLClient(http);

var getHomeWorld = Convert.ToBoolean(Random.Shared.Next(0, 2)); // Imagine this coming from user settings
// Line below produces ZQL0002: Failed to convert to graphql query: getHomeWorld ? p. Homeworld(h => h. Name) : default(string)
var result = await client.Query(o => o.Person(id: 1, selector: p => new { p.Id, p.Name, HomeWorld = getHomeWorld ? p.Homeworld(h => h.Name) : default(string) }));

Describe the solution you'd like Any solution would do, support of ternary operator from example above may be one of them.

Describe alternatives you've considered Requesting all data that may potentially be needed.

N0D4N avatar Oct 29 '24 19:10 N0D4N