diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 018147f0ab1..46b092b28aa 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -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 diff --git a/graph/src/env/graphql.rs b/graph/src/env/graphql.rs index 61296b92638..e7405998b30 100644 --- a/graph/src/env/graphql.rs +++ b/graph/src/env/graphql.rs @@ -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, + /// 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 @@ -166,6 +166,6 @@ pub struct InnerGraphQl { warn_result_size: WithDefaultUsize, { usize::MAX }>, #[envconfig(from = "GRAPH_GRAPHQL_ERROR_RESULT_SIZE", default = "")] error_result_size: WithDefaultUsize, { usize::MAX }>, - #[envconfig(from = "GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION")] - max_operations_per_connection: Option, + #[envconfig(from = "GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION", default = "1000")] + max_operations_per_connection: usize, } diff --git a/server/websocket/src/connection.rs b/server/websocket/src/connection.rs index ff0c1d41aa1..ff5563aaddf 100644 --- a/server/websocket/src/connection.rs +++ b/server/websocket/src/connection.rs @@ -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