Skip to content

Commit

Permalink
update IR::Context
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Jun 23, 2024
1 parent e783417 commit 78b6cac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/core/blueprint/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::core::blueprint::Type::ListType;
use crate::core::blueprint::*;
use crate::core::config::{Config, Enum, Field, GraphQLOperationType, Protected, Union};
use crate::core::directive::DirectiveCodec;
use crate::core::ir::model::{Cache, Context, IR};
use crate::core::ir::model::{Cache, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use crate::core::{config, scalar};
Expand Down Expand Up @@ -300,7 +300,7 @@ fn update_resolver_from_path(

process_path(context.clone()).and_then(|of_type| {
let mut updated_base_field = base_field;
let resolver = IR::Context(Context::Path(context.path.to_owned()));
let resolver = IR::ContextPath(context.path.to_owned());
if has_index {
updated_base_field.of_type =
Type::NamedType { name: of_type.name().to_string(), non_null: false }
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/modify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::blueprint::*;
use crate::core::config;
use crate::core::config::Field;
use crate::core::ir::model::{Context, IR};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;

Expand All @@ -25,7 +25,7 @@ pub fn update_modify<'a>(
b_field.resolver = Some(
b_field
.resolver
.unwrap_or(IR::Context(Context::Path(vec![b_field.name.clone()]))),
.unwrap_or(IR::ContextPath(vec![b_field.name.clone()])),
);
b_field = b_field.name(new_name.clone());
}
Expand Down
11 changes: 6 additions & 5 deletions src/core/blueprint/operators/protected.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::blueprint::FieldDefinition;
use crate::core::config::{self, ConfigModule, Field};
use crate::core::ir::model::{Context, IR};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;

Expand All @@ -27,10 +27,11 @@ pub fn update_protected<'a>(
);
}

b_field.resolver =
Some(IR::Protect(Box::new(b_field.resolver.unwrap_or(
IR::Context(Context::Path(vec![b_field.name.clone()])),
))));
b_field.resolver = Some(IR::Protect(Box::new(
b_field
.resolver
.unwrap_or(IR::ContextPath(vec![b_field.name.clone()])),
)));
}

Valid::succeed(b_field)
Expand Down
15 changes: 5 additions & 10 deletions src/core/ir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::pin::Pin;
use async_graphql_value::ConstValue;

use super::eval_io::eval_io;
use super::model::{Cache, CacheKey, Context, Map, IR};
use super::model::{Cache, CacheKey, Map, IR};
use super::{Error, EvalContext, ResolverContextLike};
use crate::core::json::JsonLike;
use crate::core::serde_value_ext::ValueExt;
Expand All @@ -21,15 +21,10 @@ impl IR {
{
Box::pin(async move {
match self {
IR::Context(op) => match op {
Context::Value => {
Ok(ctx.value().cloned().unwrap_or(async_graphql::Value::Null))
}
Context::Path(path) => Ok(ctx
.path_value(path)
.map(|a| a.into_owned())
.unwrap_or(async_graphql::Value::Null)),
},
IR::ContextPath(path) => Ok(ctx
.path_value(path)
.map(|a| a.into_owned())
.unwrap_or(async_graphql::Value::Null)),
IR::Path(input, path) => {
let inp = &input.eval(ctx).await?;
Ok(inp
Expand Down
14 changes: 4 additions & 10 deletions src/core/ir/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ use crate::core::{grpc, http};

#[derive(Clone, Debug, Display)]
pub enum IR {
Context(Context),
Dynamic(DynamicValue<Value>),
#[strum(to_string = "{0}")]
IO(IO),
Cache(Cache),

// TODO: Path can be implement using Pipe
Path(Box<IR>, Vec<String>),
ContextPath(Vec<String>),
Protect(Box<IR>),
Map(Map),
Pipe(Box<IR>, Box<IR>),
}

#[derive(Clone, Debug)]
pub enum Context {
Value,
Path(Vec<String>),
}

#[derive(Clone, Debug)]
pub struct Map {
pub input: Box<IR>,
Expand Down Expand Up @@ -134,9 +130,7 @@ impl IR {
IR::Pipe(first, second) => {
IR::Pipe(first.modify_box(modifier), second.modify_box(modifier))
}
IR::Context(ctx) => match ctx {
Context::Value | Context::Path(_) => IR::Context(ctx),
},
IR::ContextPath(path) => IR::ContextPath(path),
IR::Dynamic(_) => expr,
IR::IO(_) => expr,
IR::Cache(Cache { io, max_age }) => {
Expand Down

1 comment on commit 78b6cac

@github-actions
Copy link

Choose a reason for hiding this comment

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

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.68ms 3.17ms 95.87ms 73.53%
Req/Sec 3.79k 195.74 4.18k 91.17%

452946 requests in 30.00s, 2.27GB read

Requests/sec: 15096.42

Transfer/sec: 77.49MB

Please sign in to comment.