这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Merged
merged 40 commits into from
Mar 27, 2024
Merged

Conversation

hallettj
Copy link
Collaborator

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

@hallettj hallettj self-assigned this Mar 26, 2024
/// 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>,
Copy link
Collaborator Author

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?

Copy link
Contributor

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.

Copy link
Collaborator Author

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> {
Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Collaborator Author

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)]

Copy link
Contributor

@dmoverton dmoverton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@hallettj hallettj merged commit 5ef415d into main Mar 27, 2024
@hallettj hallettj deleted the arguments-for-native-queries branch March 27, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants