Skip to content

Commit

Permalink
add nested query in example
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Dec 20, 2024
1 parent 6096733 commit 3668ee0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions query-engine/core/src/compiler/translate/query/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub(crate) fn translate_read_query(query: ReadQuery, ctx: &Context<'_>) -> Trans
ReadQuery::ManyRecordsQuery(mrq) => {
let selected_fields = mrq.selected_fields.without_relations().into_virtuals_last();
let needs_reversed_order = mrq.args.needs_reversed_order();
dbg!(mrq.nested);

// TODO: we ignore chunking for now
let query = query_builder::read::get_records(
Expand Down
56 changes: 28 additions & 28 deletions query-engine/query-engine/examples/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use indexmap::IndexMap;
use query_core::{query_graph_builder::QueryGraphBuilder, schema::QueryTag, QueryDocument};
use request_handlers::{Action, FieldQuery, JsonBody, JsonSingleQuery, RequestBody, SelectionSet, SelectionSetValue};
use query_core::{query_graph_builder::QueryGraphBuilder, QueryDocument};
use request_handlers::{JsonBody, JsonSingleQuery, RequestBody};
use serde_json::json;

pub fn main() -> anyhow::Result<()> {
let schema_string = include_str!("./schema.prisma");
Expand All @@ -20,31 +20,31 @@ pub fn main() -> anyhow::Result<()> {
// email: Prisma.Param("userEmail")
// }
// })
let request = RequestBody::Json(JsonBody::Single(JsonSingleQuery {
model_name: Some("User".into()),
action: Action::new(QueryTag::FindMany),
query: FieldQuery {
arguments: Some({
let mut map = IndexMap::new();
map.insert(
"where".into(),
serde_json::json!({
"email": {
"$type": "Param",
"value": "userEmail",
}
}),
);
map
}),
selection: SelectionSet::new({
let mut map = IndexMap::new();
map.insert("$scalars".into(), SelectionSetValue::Shorthand(true));
map
}),
},
}));

let query: JsonSingleQuery = serde_json::from_value(json!({
"modelName": "User",
"action": "findMany",
"query": {
"arguments": {
"where": {
"email": {
"$type": "Param",
"value": "userEmail"
}
}
},
"selection": {
"$scalars": true,
"posts": {
"arguments": {},
"selection": {
"$scalars": true
}
}
}
}
}))?;

let request = RequestBody::Json(JsonBody::Single(query));
let doc = request.into_doc(&query_schema)?;

let QueryDocument::Single(query) = doc else {
Expand Down

0 comments on commit 3668ee0

Please sign in to comment.