-
Notifications
You must be signed in to change notification settings - Fork 221
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
Don't validate fields that were not passed #1184
Conversation
Hi @joesaunderson! |
I can try, there aren't many existing tests though, so not sure where I'll be starting from. |
Yep @Vincz this is a bit beyond my knowledge of this bundle, there's nothing to extend and I'm getting into the internals of the system. |
Hi @Vincz, @joesaunderson I don't understand the need for this change. I our use-case we're creating an order and filling customer data based on the input.
The validation group is then computed based on the value of the But after this change, the Can you explain the use-case benefiting from this change? And do you have an idea how to solve the case I described? |
The use case benefitting this change. Imagine a mutation like so:
Where If you only want to edit some properties of the entity, you can pass only the properties you want to edit. Previously, if you did this, it ran the validation rules for every properly of that entity (or input object in this case) regardless of whether they were passed on not. |
But that way you have to count on the data you're passing down the application. So it's really easy to make a mistake and set data that should not pass the validation. |
Not sure I fully understand your use case so forgive me... But isn't it correct that when not passing the It should only be validated when it's passed (which is when |
Where does the counting element come in to it? This way the data you pass in is validated, the data you don't pass in isn't validated? |
If I set the differentDeliveryAddress = true, the I want to validate the deliveryFirstName regardless if passed in mutation. Now I have to be sure I pass all field even though the schema do not require them, otherwise invalid data may be set |
I understand it better now. Devils advocate... if you're essentially requiring that field when differentDeliveryAddress = true, shouldn't your application ensure it's always passed too? @Vincz suggested this behaviour could be a config setting, so maybe that could be an option?
|
Hi @grossmannmartin, @joesaunderson |
I should have some time to look at it Tuesday. Can you point me in the direction of where config is used in other places? |
Hi, thanks for understanding and the dialog :) From my point of view, the original behavior is better as a default, because otherwise the rest of the application has to know what was passed as arguments and it's a behavior that already was. If necessary, I can make some time at the end of the week... sooner is not possible for me, sorry |
@Vincz @grossmannmartin I had a brief go at this today. It adds a new config option I tried to add it to the field level too (under I believe it puts us in a good place for full / partial validation. |
I discovered that this modification causes 2 validation issues in certain scenarios:
Prerequisites:
valid input data related to schema (no issues):
Scenario 1) Invalid data to bypass validation rules
Reason: Scenario 2) Internal server Error for valid data
Reason:
It gives us error: |
@ITernovtsii see #1185 I allowed the behaviour to be configurable, but I haven't had time to write tests / take it forward. Feel free to take it on if this is pressing |
@joesaunderson I think this change should be removed from the released version first, as "partial" mode will not work properly anyway, |
Partial mode does work, and is working for our use case in a production app for millions of users 😀 |
I think both your scenarios are when an input object is passed as an array, so maybe we need to adjust the check for that (does the field exist on any object in the array). |
Sorry, but I disagree that it makes sense to keep it because it works in some cases. Especially taking into account that bypass validation can be considered as a security issue. Issue is reproducible not only with arrays, but with any schema where same input type used twice in the request. For example, if you have address input type, and passing it as person's deliveryAddress plus as homeAddress. User who knows about this issue will be able to bypass validation rules, and set invalid county code to delivery address. And I don't think it will be as simple as adjust this check, as it breaks consistency. Same object will be validated differently based on another object in the request. |
There's was also another suggestion from @Vincz so allow the validation mode to be set at the config level (PR above) or at a mutation level. Maybe you could extend my PR to add that too, allowing it to be set at a mutation by mutation basis? |
This fixes the validation rules so that when passing a partial input object, only the fields passed are validated.