Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get field optionally #116

Open
N0D4N opened this issue Oct 29, 2024 · 0 comments
Open

Ability to get field optionally #116

N0D4N opened this issue Oct 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@N0D4N
Copy link

N0D4N commented Oct 29, 2024

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 N0D4N added the enhancement New feature or request label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant