-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add query complexity and depth support in server directive #2828
Draft
laststylebender14
wants to merge
34
commits into
main
Choose a base branch
from
feat/add-query-complexity-and-depth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9edd1d0
- added transforms for rules.
laststylebender14 6a550b3
- impl rules
laststylebender14 000f018
- move calculations to specific rules
laststylebender14 cb109b5
- remove un-used test
laststylebender14 7bec760
- removed
laststylebender14 35da5b8
- lint formatting
laststylebender14 48f2e4e
- used associated types
laststylebender14 bbdcb49
- added test cases
laststylebender14 2adc5f4
- fix the Value to ConstValue
laststylebender14 d756b26
- fix constvalue and value issue.
laststylebender14 3aa2424
- take query complexity and depth from server directive.
laststylebender14 5db2d92
- add when operator to rule
laststylebender14 8054dd9
- apply rules conditionally.
laststylebender14 72bb868
- auto updated
laststylebender14 3fc1b4f
- updated snap: added server to index.
laststylebender14 5ed4208
- made rules generic over T.
laststylebender14 a864282
Merge branch 'main' into feat/add-query-complexity-and-depth
laststylebender14 f06a19d
- added default to ensure only applied setting is executed.
laststylebender14 b5fd2cb
- auto generated.
laststylebender14 ff3844f
- updated error msg.
laststylebender14 c9d3518
- apply setting only when flag is true.
laststylebender14 d335da0
- lint fixes
laststylebender14 6ed10b6
Merge branch 'main' into feat/add-query-complexity-and-depth
laststylebender14 03ce3f4
- rename trait to ExecutionRule
laststylebender14 1969d62
- fix ci tests.
laststylebender14 80c9965
- lint fixes
laststylebender14 ebbd47f
- added integration test for query complexity
laststylebender14 2ef01f2
- added integration test for query depth
laststylebender14 b182614
- lint fixes
laststylebender14 8d011d7
Merge branch 'main' into feat/add-query-complexity-and-depth
laststylebender14 ef198aa
- instead of converting use validationerror as variant in build error…
laststylebender14 0d40854
- iterate over iterator instead of converting to vec.
laststylebender14 9b707f8
- removed pub
laststylebender14 5cd51b8
- clean up - use iter_only to iterate over field.
laststylebender14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use super::OperationPlan; | ||
use crate::core::valid::{Valid, Validator}; | ||
|
||
mod query_complexity; | ||
mod query_depth; | ||
|
||
pub use query_complexity::QueryComplexity; | ||
pub use query_depth::QueryDepth; | ||
|
||
pub trait ExecutionRule { | ||
fn validate<T: std::fmt::Debug>(&self, plan: &OperationPlan<T>) -> Valid<(), String>; | ||
} | ||
|
||
pub trait RuleOps: Sized + ExecutionRule { | ||
fn pipe<Other: ExecutionRule>(self, other: Other) -> Pipe<Self, Other> { | ||
Pipe(self, other) | ||
} | ||
fn when(self, cond: bool) -> When<Self> { | ||
When(self, cond) | ||
} | ||
} | ||
|
||
impl<T: ExecutionRule> RuleOps for T {} | ||
|
||
pub struct Pipe<A, B>(A, B); | ||
|
||
impl<A, B> ExecutionRule for Pipe<A, B> | ||
where | ||
A: ExecutionRule, | ||
B: ExecutionRule, | ||
{ | ||
fn validate<T: std::fmt::Debug>(&self, plan: &OperationPlan<T>) -> Valid<(), String> { | ||
self.0.validate(plan).and_then(|_| self.1.validate(plan)) | ||
} | ||
} | ||
|
||
pub struct When<A>(A, bool); | ||
|
||
impl<A> ExecutionRule for When<A> | ||
where | ||
A: ExecutionRule, | ||
{ | ||
fn validate<T: std::fmt::Debug>(&self, plan: &OperationPlan<T>) -> Valid<(), String> { | ||
if self.1 { | ||
self.0.validate(plan) | ||
} else { | ||
Valid::succeed(()) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Rules; | ||
|
||
impl ExecutionRule for Rules { | ||
fn validate<T: std::fmt::Debug>(&self, _: &OperationPlan<T>) -> Valid<(), String> { | ||
Valid::succeed(()) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Store the computed query depth in the plan. The builder should not fail if depth or complexity thresholds are exceeded.