feat: change arg format of update mutations #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
the old format encouraged sending unnecessary data and did not guard against bugs from sending extra data
Description
Doing e.g. a site update mutation before would look like:
but could look like this if e.g. we had a site object that already had the new data on it, which is much more tempting
the second one is bad for a few reasons:
updateSite
method, but that doesn't solve the second problem and restricting the fields is finnicky and we have to remember to update it all the timeif we simply remembered to never do something like the second thing it would be ok, but there's nothing prevent us from doing it except our brain. this PR creates a helper type and validation function to make the args for updates look like this:
this isn't perfect, it would still e.g. admit the following:
but i'm hoping that will be a less intuitive thing to do, and also we can do a runtime client-side check with this format so it'll be easier to catch in tests. there is unfortunately no way to give
update
a type that says "reject arguments that have an id field" as far as i know in TypeScript so it can't be a compile-time checkdoes this seem like a worthwhile thing to do? or should we just remember not to do
?