-
Notifications
You must be signed in to change notification settings - Fork 1
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
Revise the mutations API #501
Conversation
@@ -20,15 +22,9 @@ pub struct InsertMutation { | |||
pub description: String, | |||
pub schema_name: sql::ast::SchemaName, | |||
pub table_name: sql::ast::TableName, | |||
pub objects_argument_name: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we can specify the name once instead of having magic strings.
b3e0fe3
to
76773c4
Compare
@@ -119,7 +115,7 @@ pub fn translate( | |||
.iter() | |||
.map(|by_column| { | |||
let unique_key = arguments | |||
.get(&by_column.name) | |||
.get(&format!("{}{}", columns_prefix, by_column.name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the arguments
map should use a tuple or something as a key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments comes from ndc-spec, and they are not used only for keys, but also for update_columns
, pre_check
, etc.
I agree that this isn't looking great, but I'm not sure there's a nicer solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, makes sense.
.get(&filter.argument_name) | ||
.ok_or(Error::ArgumentNotFound(filter.argument_name.clone()))?; | ||
.get(&pre_check.argument_name) | ||
.ok_or(Error::ArgumentNotFound(pre_check.argument_name.clone()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ok_or(Error::ArgumentNotFound(pre_check.argument_name.clone()))?; | |
.ok_or_else(|| Error::ArgumentNotFound(pre_check.argument_name.clone()))?; |
"array of values structure in insert _objects argument. Expecting an array of objects." | ||
.to_string(), | ||
)), | ||
serde_json::Value::Array(_) => Err(Error::UnexpectedStructure(format!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this in the Display
impl of UnexpectedStructure
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment made sense to me. I went to have a look what would I need to parameterize UnexpectedStructure by to make this work, and the result was:
- array of arrays
- insert
- {} argument
- an array of objects
Which is essentially almost the entire message :( Might not be worth trying to parameterize in that case, and we probably don't need a dedicated error time for each unexpected structure.
.get("_objects") | ||
.ok_or(Error::ArgumentNotFound("_objects".to_string()))?; | ||
.get(&mutation.objects_argument_name) | ||
.ok_or(Error::ArgumentNotFound( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ok_or(Error::ArgumentNotFound( | |
.ok_or_else(|| Error::ArgumentNotFound( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went to have a look. It seems like .ok_or_else
is useful when the or_else part is an expensive computation. This isn't the case here - we need to create a closure that returns this particular data, I think this will end up doing more work and require more memory, won't it? So isn't it strictly worse than just ok_or
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just because of the .clone()
; I think it's probably borderline.
Co-authored-by: Samir Talwar <samir.talwar@hasura.io>
What
We want to make the api for mutations pretty. We make the following changes:
key_
How
General design
Note that the
update_columns
structure is different than the v2 version where we had_set
,_inc
, and other fields.by_column_and_column_and_column
instead of the db constraint name, because the former is far more helpful.key_
.