Skip to content

Commit

Permalink
subscriptions: set maximum operations per connection
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens committed Jul 14, 2022
1 parent a66caaf commit 9d0655c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ happens, subgraphs might process inconsistent data. Defaults to 250.
value for both is unlimited.
- `GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION`: maximum number of GraphQL
operations per WebSocket connection. Any operation created after the limit
will return an error to the client. Default: unlimited.
will return an error to the client. Default: 1000.
- `GRAPH_GRAPHQL_HTTP_PORT` : Port for the GraphQL HTTP server
- `GRAPH_GRAPHQL_WS_PORT` : Port for the GraphQL WebSocket server
- `GRAPH_SQL_STATEMENT_TIMEOUT`: the maximum number of seconds an
Expand Down
10 changes: 5 additions & 5 deletions graph/src/env/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub struct EnvVarsGraphQl {
/// Set by the environment variable `GRAPH_GRAPHQL_ERROR_RESULT_SIZE`. The
/// default value is [`usize::MAX`].
pub error_result_size: usize,
/// Set by the flag `GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION`. No
/// default is provided.
pub max_operations_per_connection: Option<usize>,
/// Set by the flag `GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION`.
/// Defaults to 1000.
pub max_operations_per_connection: usize,
}

// This does not print any values avoid accidentally leaking any sensitive env vars
Expand Down Expand Up @@ -166,6 +166,6 @@ pub struct InnerGraphQl {
warn_result_size: WithDefaultUsize<NoUnderscores<usize>, { usize::MAX }>,
#[envconfig(from = "GRAPH_GRAPHQL_ERROR_RESULT_SIZE", default = "")]
error_result_size: WithDefaultUsize<NoUnderscores<usize>, { usize::MAX }>,
#[envconfig(from = "GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION")]
max_operations_per_connection: Option<usize>,
#[envconfig(from = "GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION", default = "1000")]
max_operations_per_connection: usize,
}
18 changes: 7 additions & 11 deletions server/websocket/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,13 @@ where
);
}

if let Some(max_ops) = ENV_VARS.graphql.max_operations_per_connection {
if operations.operations.len() >= max_ops {
return send_error_string(
&msg_sink,
id,
format!(
"Reached the limit of {} operations per connection",
max_ops
),
);
}
let max_ops = ENV_VARS.graphql.max_operations_per_connection;
if operations.operations.len() >= max_ops {
return send_error_string(
&msg_sink,
id,
format!("Reached the limit of {} operations per connection", max_ops),
);
}

// Parse the GraphQL query document; respond with a GQL_ERROR if
Expand Down

0 comments on commit 9d0655c

Please sign in to comment.