Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Sep 12, 2024
1 parent 3270242 commit bedc4f0
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 32 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions projects/ssddOnTop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ futures-util = "0.3.30"
http = "1.1.0"
url = "2.5.2"
schemars = {version = "0.8.17", features = ["derive"]}
async-recursion = "1.1.1"

[dev-dependencies]
http-cache = "0.18.0"
6 changes: 6 additions & 0 deletions projects/ssddOnTop/src/blueprint/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct FieldHash {
pub id: TypeName,
}

impl FieldHash {
pub fn new(name: FieldName, id: TypeName) -> Self {
Self { name, id }
}
}

#[derive(Debug)]
pub struct Blueprint {
pub fields: HashMap<FieldHash, Field>,
Expand Down
34 changes: 9 additions & 25 deletions projects/ssddOnTop/src/http/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::request_context::RequestContext;
use crate::value::Value;
use bytes::Bytes;
use http_body_util::Full;
use crate::jit::model::PathFinder;

pub async fn handle_request(
req: Request,
Expand All @@ -34,31 +35,14 @@ async fn handle_gql_req(
let gql_req: async_graphql::Request = serde_json::from_slice(&request.body)?;
let doc = async_graphql::parser::parse_query(&gql_req.query)?;
let req_ctx = create_request_context(&app_ctx);
if let Some(query) = app_ctx.blueprint.schema.query.as_ref() {
let mut eval_ctx = EvalContext::new(&req_ctx);
let x = app_ctx.blueprint.fields.get(&FieldHash {
name: FieldName("post".to_string()),
id: TypeName(query.to_string()),
});
let x = x.as_ref().unwrap().ir.as_ref().unwrap();
let mut map = serde_json::Map::new();
let key = "id".to_string();
let val = serde_json::Value::Number(serde_json::Number::from(1));
map.insert(key, val);
eval_ctx = eval_ctx.with_args(Value::new(serde_json::Value::Object(map)));

let x = x.eval(&mut eval_ctx).await?;
println!("{}", x);
/*for (_,field) in app_ctx.blueprint.fields.iter() {
if let Some(ir) = field.ir.as_ref() {
println!("hx: {}", field.name.as_ref());
println!("{}", ir.eval(&mut eval_ctx).await?);
}else {
println!("hx1: {}", field.name.as_ref());
}
}*/
Ok(hyper::Response::new(Full::new(Bytes::from_static(
b"Printed",
if let Some(_) = app_ctx.blueprint.schema.query.as_ref() {
let eval_ctx = EvalContext::new(&req_ctx);
let path_finder = PathFinder::new(doc, &app_ctx.blueprint);
let fields = path_finder.exec().await;
let resolved = fields.resolve(eval_ctx).await?;
let finalized = resolved.finalize();
Ok(hyper::Response::new(Full::new(Bytes::from(
finalized.to_string(),
))))
} else {
Ok(hyper::Response::new(Full::new(Bytes::from_static(
Expand Down
14 changes: 13 additions & 1 deletion projects/ssddOnTop/src/ir/eval_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct EvalContext<'a> {
pub request_ctx: &'a RequestContext,

// graphql_ctx: &'a Ctx,
graphql_ctx_value: Option<Value>,
pub graphql_ctx_value: Option<Value>,

graphql_ctx_args: Option<Value>,
}
Expand All @@ -33,6 +33,18 @@ impl<'a> EvalContext<'a> {
..self
}
}
pub fn clear_args(self) -> Self {
Self {
graphql_ctx_args: None,
..self
}
}
pub fn clear_value(self) -> Self {
Self {
graphql_ctx_value: None,
..self
}
}
pub fn path_arg<T: AsRef<str>>(&self, path: &[T]) -> Option<Cow<'a, Value>> {
let args = self.graphql_ctx_args.as_ref()?;
get_path_value(args, path).map(|a| Cow::Owned(a.clone()))
Expand Down
2 changes: 1 addition & 1 deletion projects/ssddOnTop/src/jit/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod model;
pub mod model;
Loading

0 comments on commit bedc4f0

Please sign in to comment.