-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jit): plan ahead auth requirements when required (#3139)
Co-authored-by: Tushar Mathur <[email protected]>
- Loading branch information
1 parent
847d1da
commit 4e0979c
Showing
26 changed files
with
228 additions
and
120 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use std::convert::Infallible; | ||
|
||
use tailcall_valid::Valid; | ||
|
||
use crate::core::blueprint::DynamicValue; | ||
use crate::core::ir::model::IR; | ||
use crate::core::jit::{Field, OperationPlan}; | ||
use crate::core::Transform; | ||
|
||
pub struct AuthPlaner<A> { | ||
marker: std::marker::PhantomData<A>, | ||
} | ||
|
||
impl<A> AuthPlaner<A> { | ||
pub fn new() -> Self { | ||
Self { marker: std::marker::PhantomData } | ||
} | ||
} | ||
|
||
impl<A> Transform for AuthPlaner<A> { | ||
type Value = OperationPlan<A>; | ||
type Error = Infallible; | ||
|
||
fn transform(&self, mut plan: Self::Value) -> Valid<Self::Value, Self::Error> { | ||
let mut before = Vec::new(); | ||
|
||
plan.selection = plan | ||
.selection | ||
.into_iter() | ||
.map(|field| drop_protect_field(&mut before, field)) | ||
.collect(); | ||
let ir = before.into_iter(); | ||
|
||
plan.before = match plan.before { | ||
Some(before) => Some(ir.fold(before, |a, b| a.pipe(b))), | ||
None => ir.reduce(|a, b| a.pipe(b)), | ||
}; | ||
Valid::succeed(plan) | ||
} | ||
} | ||
|
||
/// Used to recursively update the field ands its selections to remove | ||
/// IR::Protected | ||
fn drop_protect_field<A>(before: &mut Vec<IR>, mut field: Field<A>) -> Field<A> { | ||
if let Some(mut ir) = field.ir { | ||
let is_protected = drop_protect_ir(&mut ir); | ||
|
||
field.selection = field | ||
.selection | ||
.into_iter() | ||
.map(|field| drop_protect_field(before, field)) | ||
.collect(); | ||
|
||
if is_protected { | ||
let ir = IR::Protect(Box::new(IR::Dynamic(DynamicValue::Value( | ||
Default::default(), | ||
)))); | ||
before.push(ir); | ||
} | ||
|
||
field.ir = Some(ir); | ||
} | ||
field | ||
} | ||
|
||
/// This function modifies an IR chain by detecting and removing any | ||
/// instances of IR::Protect from the chain. Returns `true` when it modifies the | ||
/// IR. | ||
pub fn drop_protect_ir(ir: &mut IR) -> bool { | ||
match ir { | ||
IR::Dynamic(_) => false, | ||
IR::IO(_) => false, | ||
IR::Cache(_) => false, | ||
IR::Path(ir, _) => drop_protect_ir(ir), | ||
IR::ContextPath(_) => false, | ||
IR::Protect(inner_ir) => { | ||
*ir = *inner_ir.clone(); | ||
true | ||
} | ||
IR::Map(_) => false, | ||
IR::Pipe(ir1, ir2) => drop_protect_ir(ir1) || drop_protect_ir(ir2), | ||
IR::Discriminate(_, ir) => drop_protect_ir(ir), | ||
IR::Entity(_) => false, | ||
IR::Service(_) => false, | ||
} | ||
} |
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
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
Oops, something went wrong.
4e0979c
There was a problem hiding this comment.
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
755631 requests in 30.01s, 3.79GB read
Requests/sec: 25177.45
Transfer/sec: 129.23MB