-
Notifications
You must be signed in to change notification settings - Fork 3
arguments for read-write native queries #16
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
Conversation
/// given `command`. | ||
/// | ||
/// Argument values are standard JSON mapped from GraphQL input types, not Extended JSON. | ||
/// Values will be converted to BSON according to the types specified here. | ||
#[serde(default)] | ||
pub arguments: BTreeMap<String, ObjectField>, |
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.
Technically this field should be called parameters
. Is it worth changing?
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.
If parameters
is what we use elsewhere for native queries then it's probably worth changing, given that users will need to write these.
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.
ndc-postgres uses the name arguments
which is what I copied here. It's just that technically they're wrong: parameters are input variables, arguments are the values that bind to parameters. But I can see the argument that consistency is more important than technical correctness.
} | ||
|
||
/// Works like json_to_bson, but only converts BSON scalar types. | ||
pub fn json_to_bson_scalar(expected_type: BsonScalarType, value: Value) -> Result<Bson> { |
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.
@daniel-chambers when you've propagated the type information through this should be helpful for correctly handling ObjectIDs, dates, etc.
}; | ||
|
||
let input = json!({ | ||
"double": 3.14159, |
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.
Clippy really doesn't like you trying to impersonate pi. I found that with one of my test cases too 😂
https://github.com/hasura/ndc-mongodb/actions/runs/8446549353/job/23135506300?pr=16#step:6:163
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.
That's hilarious. And something I didn't realize is that the CI setup is running lints on test code, while it looks like when I run cargo clippy
locally it doesn't check anything annotated with #[cfg(test)]
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.
Looks good
Hooks up native query arguments, but only for mutations for this PR. Converts JSON argument values to BSON according to the native query's parameter types. Implements a system to interpolate argument values into the BSON command document sent to MongoDB.
I'm going to handle arguments for read-only native queries in a follow-up PR since I realized that there is still more to do to resolve arguments in the presence of query variables.
It turns out that the earlier change I made to switch configuration fields to maps broke YAML deserialization due to a bug described here: dtolnay/serde-yaml#344. So I've converted the native query fixtures to JSON for the time being. We'll have to either find a workaround for that bug, or disable YAML parsing. I'm inclined to do a bit of work to try for a workaround since I think the YAML format is nicer for working with: it's much less verbose, and I had to delete a comment I had in one fixture because JSON.
Ticket: https://hasurahq.atlassian.net/browse/MDB-87