Skip to content

Commit

Permalink
[chore][GraphQL/Limits] Standardise query_limits_checker file order (M…
Browse files Browse the repository at this point in the history
…ystenLabs#18663)

## 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

## Stack
- MystenLabs#18660
- MystenLabs#18661 
- MystenLabs#18662 

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
amnn authored and tx-tomcat committed Jul 29, 2024
1 parent d4a7b7c commit 239de0c
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 239de0c

Please sign in to comment.