Skip to content

Commit

Permalink
[chore][GraphQL/Limits] Standardise query_limits_checker file order
Browse files Browse the repository at this point in the history
## Description

This is a file order change only, with no other meaningful changes. It
standardises the order to:

- Constants
- Types
- Impls
- Trait Impls
- Free functions

## Test plan

CI
  • Loading branch information
amnn committed Jul 16, 2024
1 parent 3d28d16 commit 375b98a
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ use tokio::sync::Mutex;
use tracing::info;
use uuid::Uuid;

pub(crate) const CONNECTION_FIELDS: [&str; 2] = ["edges", "nodes"];

/// Extension factory for adding checks that the query is within configurable limits.
pub(crate) struct QueryLimitsChecker;

#[derive(Debug, Default)]
struct QueryLimitsCheckerExt {
validation_result: Mutex<Option<ValidationRes>>,
}

/// Only display usage information if this header was in the request.
pub(crate) struct ShowUsage;

Expand All @@ -39,13 +46,13 @@ struct ValidationRes {
query_payload: u32,
}

#[derive(Debug, Default)]
struct QueryLimitsCheckerExt {
validation_result: Mutex<Option<ValidationRes>>,
#[derive(Debug)]
struct ComponentCost {
pub input_nodes: u32,
pub output_nodes: u32,
pub depth: u32,
}

pub(crate) const CONNECTION_FIELDS: [&str; 2] = ["edges", "nodes"];

impl ShowUsage {
pub(crate) fn name() -> &'static HeaderName {
&LIMITS_HEADER
Expand All @@ -60,25 +67,6 @@ impl ExtensionFactory for QueryLimitsChecker {
}
}

#[derive(Debug)]
struct ComponentCost {
pub input_nodes: u32,
pub output_nodes: u32,
pub depth: u32,
}

impl std::ops::Add for ComponentCost {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self {
input_nodes: self.input_nodes + rhs.input_nodes,
output_nodes: self.output_nodes + rhs.output_nodes,
depth: self.depth + rhs.depth,
}
}
}

#[async_trait::async_trait]
impl Extension for QueryLimitsCheckerExt {
async fn request(&self, ctx: &ExtensionContext<'_>, next: NextRequest<'_>) -> Response {
Expand Down Expand Up @@ -210,6 +198,18 @@ impl Extension for QueryLimitsCheckerExt {
}
}

impl std::ops::Add for ComponentCost {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self {
input_nodes: self.input_nodes + rhs.input_nodes,
output_nodes: self.output_nodes + rhs.output_nodes,
depth: self.depth + rhs.depth,
}
}
}

/// Parse the selected fields in one operation and check if it conforms to configured limits.
fn analyze_selection_set(
limits: &Limits,
Expand Down

0 comments on commit 375b98a

Please sign in to comment.