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

Allow for partial updates by ignoring missing input fields #7948

Open
maurice-freitag opened this issue Jan 23, 2025 · 3 comments
Open

Allow for partial updates by ignoring missing input fields #7948

maurice-freitag opened this issue Jan 23, 2025 · 3 comments

Comments

@maurice-freitag
Copy link

Product

Hot Chocolate

Is your feature request related to a problem?

I have defined a mutation to update an object. _id is a required parameter, everything else is optional. When I send one such query and only set a few of these properties, the context is still populated with the missing fields as soon as our middleware is hit, all of them having null values. We would like to support partial updates, so an input object only containing only the fields the user actually set would be preferred. The current implementation makes it impossible to determine if the user wanted to set a value to null explicitly or chose to not update the missing fields at all.

Image

I tracked the issue down to the InputParser, the missing values seem to be populated here.

The solution you'd like

Allow configuring the input parser to support the desired behavior.

@maurice-freitag
Copy link
Author

I created a PR to illustrate the required changes. I also added a simple test for the new behavior but can't get it to run because it's missing some instances of the tested components.

See #7949

@michaelstaib
Copy link
Member

Thats what IOptional is for in HotChocolate. It still follows the GraphQL input coercion but tells you that the value was produced by a default. I am going to close your PR as we will not include it. We can discuss what IOptional is lacking and can improve it.

@maurice-freitag
Copy link
Author

maurice-freitag commented Jan 23, 2025

But IOptional doesn't really solve the issue, does it? As soon as the actual execution of the mutation starts, the input object is already populated with default values the user didn't provide. As far as I understand it there is no way of reproducing the caller's intention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants