Skip to content

Ability to get field optionally #116

@N0D4N

Description

@N0D4N

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions