Commit d4b7d853 authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

implement limit offset

parent a04ab107
Showing with 34 additions and 3 deletions
+34 -3
......@@ -310,8 +310,8 @@ pub struct GQLSearchArgs {
pub rowids: Option<Vec<Rowid>>, // TODO rowids should be in filters
pub sort_property: String,
pub sort_order: SortOrder,
pub limit: Option<u64>,
pub offset: Option<u64>,
pub limit: Option<u32>,
pub offset: Option<u32>,
// pub filters: Option<Vec<Filter>>,
}
......
......@@ -24,6 +24,7 @@ use crate::error::Error;
use crate::error::Result;
use crate::graphql_utils;
use crate::graphql_utils::QueryASTNode;
use crate::graphql_utils::Argument;
use crate::plugin_auth_crypto::DatabaseKey;
use crate::schema;
use crate::schema::validate_property_name;
......@@ -454,11 +455,25 @@ fn gql_search_recursive(
item_rowids: Option<Vec<Rowid>>,
level: u32
) -> Result<Vec<Value>> {
// TODO limit, sorting, filters
let mut limit: Option<u32> = None;
let mut offset: Option<u32> = None;
//let filters = Vec::new();
for argument in &query_ast.arguments {
match argument {
Argument::Limit {value} => limit = Some(*value),
Argument::Offset {value} => offset = Some(*value),
}
}
let query = GQLSearchArgs {
_type: query_ast.item_type.to_owned(),
properties: query_ast.properties.to_owned(),
rowids: item_rowids,
limit,
offset,
..Default::default()
};
let now = Instant::now();
......@@ -795,6 +810,22 @@ mod tests {
// print!("{:}", serde_json::to_string_pretty(&json!(data)).unwrap());
assert_eq!(items_with_friends.count(), 100);
let query = "
query {
Person (limit: 10, offset: 5) {
id
friend {
id
}
}
}"
.to_owned();
let res = graphql(&tx, &schema, query);
let data = res.unwrap();
let data = data.get("data").unwrap();
assert_eq!(data.len(), 10);
}
#[test]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment