-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement read-only native queries with no arguments (#5)
Implements read-only native queries without arguments. I added a test query called `hello` to the fixtures. If you run with `arion up -d` and access graphiql at http://localhost:7100/ you can try it out. I also added on `objectTypes` field to native query definitions. Object types defined there are merged with object types in `schema.json` so that users can keep hand-written types separate from generated ones. I made some changes to `directory.rs` to add more context to configuration-parsing errors in a couple of spots. If we just stick to `io::Error` errors the messages end up being not very helpful. Still to do in follow-up PRs: - implement arguments - add mutation capability to the connector - add a mutation endpoint to handle procedures Ticket: https://hasurahq.atlassian.net/browse/MDB-85
- Loading branch information
Showing
15 changed files
with
1,015 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
crates/mongodb-agent-common/src/query/execute_native_query_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use configuration::native_queries::NativeQuery; | ||
use dc_api::JsonResponse; | ||
use dc_api_types::{QueryResponse, ResponseFieldValue, RowSet}; | ||
use mongodb::Database; | ||
|
||
use crate::interface_types::MongoAgentError; | ||
|
||
pub async fn handle_native_query_request( | ||
native_query: NativeQuery, | ||
database: Database, | ||
) -> Result<JsonResponse<QueryResponse>, MongoAgentError> { | ||
let result = database | ||
.run_command(native_query.command, native_query.selection_criteria) | ||
.await?; | ||
let result_json = | ||
serde_json::to_value(result).map_err(|err| MongoAgentError::AdHoc(err.into()))?; | ||
|
||
// A function returs a single row with a single column called `__value` | ||
// https://hasura.github.io/ndc-spec/specification/queries/functions.html | ||
let response_row = [( | ||
"__value".to_owned(), | ||
ResponseFieldValue::Column(result_json), | ||
)] | ||
.into_iter() | ||
.collect(); | ||
|
||
Ok(JsonResponse::Value(QueryResponse::Single(RowSet { | ||
aggregates: None, | ||
rows: Some(vec![response_row]), | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.