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

Only serialize properties that have been assigned #118

Open
NickStrupat opened this issue Dec 3, 2024 · 3 comments
Open

Only serialize properties that have been assigned #118

NickStrupat opened this issue Dec 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@NickStrupat
Copy link
Contributor

NickStrupat commented Dec 3, 2024

Currently, ZeroQL will serialize a model to JSON text with all the properties, regardless of whether or not they've been assigned, except properties that have a value of null.

This is a problem for any nullable properties that should, during a mutation, be assigned to a value of null.

I propose that models should track which properties have been assigned, and only properties that have been assigned should be in the resulting payload to the server.

Below is an example of a possible implementation of what the generated model code would be...

class Foo
{
    private readonly Dictionary<string, object> assignedProperties = new(); // all models would have this field

    private string? text;
    public string? Text { get => text; set => assignedProperties["Text"] = text = value; }

    private int count;
    public int Count { get => text; set => assignedProperties["Count"] = text = value; }
}

And then whenever serialization happens, it would serialize foo.assignedProperties instead of foo itself.

@NickStrupat NickStrupat added the enhancement New feature or request label Dec 3, 2024
@NickStrupat
Copy link
Contributor Author

Hmm, that implementation idea wouldn't really help for the opposite: querying partial entities.

This might need something like Optional<T> for each property.

@byme8
Copy link
Owner

byme8 commented Dec 5, 2024

I saw that the StrawberryShake graphql client from HotChocolate is doing something similar like your first suggestion.

I have been thinking about adding it but never got a good use-case while using the ZeroQL.

@NickStrupat
Copy link
Contributor Author

What about making a base class/interface for generated DTOs, and making it partial.

That way folks could add custom logic/validation with things like https://github.com/Fody/PropertyChanged. What I proposed could be implemented with that, I'm pretty sure...

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

2 participants