Skip to content

Commit f7bfca8

Browse files
committed
graph, graphql: add sql service config toggle
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent d246667 commit f7bfca8

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

graph/src/env/graphql.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub struct EnvVarsGraphQl {
9292
/// Set by the flag `GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS`. Off by default.
9393
/// Disables AND/OR filters
9494
pub disable_bool_filters: bool,
95+
/// Set by the flag `GRAPH_GRAPHQL_ENABLE_SQL_SERVICE`. Off by default.
96+
/// Enables queries on the `sql()` field of the root query
97+
pub enable_sql_service: bool,
9598
/// Set by the flag `GRAPH_GRAPHQL_DISABLE_CHILD_SORTING`. Off by default.
9699
/// Disables child-based sorting
97100
pub disable_child_sorting: bool,
@@ -146,6 +149,7 @@ impl From<InnerGraphQl> for EnvVarsGraphQl {
146149
error_result_size: x.error_result_size.0 .0,
147150
max_operations_per_connection: x.max_operations_per_connection,
148151
disable_bool_filters: x.disable_bool_filters.0,
152+
enable_sql_service: x.enable_sql_service.0,
149153
disable_child_sorting: x.disable_child_sorting.0,
150154
query_trace_token: x.query_trace_token,
151155
parallel_block_constraints: x.parallel_block_constraints.0,
@@ -198,6 +202,8 @@ pub struct InnerGraphQl {
198202
pub disable_bool_filters: EnvVarBoolean,
199203
#[envconfig(from = "GRAPH_GRAPHQL_DISABLE_CHILD_SORTING", default = "false")]
200204
pub disable_child_sorting: EnvVarBoolean,
205+
#[envconfig(from = "GRAPH_GRAPHQL_ENABLE_SQL_SERVICE", default = "false")]
206+
pub enable_sql_service: EnvVarBoolean,
201207
#[envconfig(from = "GRAPH_GRAPHQL_TRACE_TOKEN", default = "")]
202208
query_trace_token: String,
203209
#[envconfig(from = "GRAPH_PARALLEL_BLOCK_CONSTRAINTS", default = "false")]

graph/src/schema/api.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ pub(in crate::schema) fn api_schema(
363363
// Refactor: Don't clone the schema.
364364
let mut api = init_api_schema(input_schema)?;
365365
add_meta_field_type(&mut api.document);
366-
add_sql_field_type(&mut api.document);
366+
367+
if ENV_VARS.graphql.enable_sql_service {
368+
add_sql_field_type(&mut api.document);
369+
}
367370
add_types_for_object_types(&mut api, input_schema)?;
368371
add_types_for_interface_types(&mut api, input_schema)?;
369372
add_types_for_aggregation_types(&mut api, input_schema)?;
@@ -1084,7 +1087,9 @@ fn add_query_type(api: &mut s::Document, input_schema: &InputSchema) -> Result<(
10841087
fields.append(&mut agg_fields);
10851088
fields.append(&mut fulltext_fields);
10861089
fields.push(meta_field());
1087-
fields.push(sql_field());
1090+
if ENV_VARS.graphql.enable_sql_service {
1091+
fields.push(sql_field());
1092+
}
10881093

10891094
let typedef = s::TypeDefinition::Object(s::ObjectType {
10901095
position: Pos::default(),
@@ -1183,7 +1188,10 @@ fn add_subscription_type(
11831188
.collect::<Vec<s::Field>>();
11841189
fields.append(&mut agg_fields);
11851190
fields.push(meta_field());
1186-
fields.push(sql_field());
1191+
1192+
if ENV_VARS.graphql.enable_sql_service {
1193+
fields.push(sql_field());
1194+
}
11871195

11881196
let typedef = s::TypeDefinition::Object(s::ObjectType {
11891197
position: Pos::default(),

graphql/src/store/resolver.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ impl StoreResolver {
283283
}
284284

285285
fn handle_sql(&self, field: &a::Field) -> Result<r::Value, QueryExecutionError> {
286-
287286
let input = field
288287
.argument_value("input")
289288
.ok_or_else(|| QueryExecutionError::EmptyQuery)?;
@@ -414,7 +413,7 @@ impl Resolver for StoreResolver {
414413
return self.lookup_meta(field).await;
415414
}
416415

417-
if object_type.is_sql() {
416+
if ENV_VARS.graphql.enable_sql_service && object_type.is_sql() {
418417
return self.handle_sql(field);
419418
}
420419

0 commit comments

Comments
 (0)