Skip to content

Commit

Permalink
graphql: env variable to disable filters
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Nov 9, 2022
1 parent 098e39f commit 9bc891a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ those.
- `SILENT_GRAPHQL_VALIDATIONS`: If `ENABLE_GRAPHQL_VALIDATIONS` is enabled, you are also able to just
silently print the GraphQL validation errors, without failing the actual query. Note: queries
might still fail as part of the later stage validations running, during GraphQL engine execution.
- `GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS`: disables the ability to use AND/OR filters. This is useful if we want to disable filters because of performance reasons.

### GraphQL caching

Expand Down
6 changes: 6 additions & 0 deletions graph/src/env/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ pub struct EnvVarsGraphQl {
/// Set by the flag `GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION`.
/// Defaults to 1000.
pub max_operations_per_connection: usize,
/// Set by the flag `GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS`. Off by default.
/// Disables AND/OR filters
pub disable_bool_filters: bool,
}

// This does not print any values avoid accidentally leaking any sensitive env vars
Expand Down Expand Up @@ -128,6 +131,7 @@ impl From<InnerGraphQl> for EnvVarsGraphQl {
warn_result_size: x.warn_result_size.0 .0,
error_result_size: x.error_result_size.0 .0,
max_operations_per_connection: x.max_operations_per_connection,
disable_bool_filters: x.disable_bool_filters.0,
}
}
}
Expand Down Expand Up @@ -173,4 +177,6 @@ pub struct InnerGraphQl {
error_result_size: WithDefaultUsize<NoUnderscores<usize>, { usize::MAX }>,
#[envconfig(from = "GRAPH_GRAPHQL_MAX_OPERATIONS_PER_CONNECTION", default = "1000")]
max_operations_per_connection: usize,
#[envconfig(from = "GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS", default = "false")]
pub disable_bool_filters: EnvVarBoolean,
}
38 changes: 22 additions & 16 deletions graphql/src/schema/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,29 @@ fn add_filter_type(
let mut generated_filter_fields = field_input_values(schema, fields)?;
generated_filter_fields.push(block_changed_filter_argument());

generated_filter_fields.push(InputValue {
position: Pos::default(),
description: None,
name: "and".to_string(),
value_type: Type::ListType(Box::new(Type::NamedType(filter_type_name.to_owned()))),
default_value: None,
directives: vec![],
});
if !ENV_VARS.graphql.disable_bool_filters {
generated_filter_fields.push(InputValue {
position: Pos::default(),
description: None,
name: "and".to_string(),
value_type: Type::ListType(Box::new(Type::NamedType(
filter_type_name.to_owned(),
))),
default_value: None,
directives: vec![],
});

generated_filter_fields.push(InputValue {
position: Pos::default(),
description: None,
name: "or".to_string(),
value_type: Type::ListType(Box::new(Type::NamedType(filter_type_name.to_owned()))),
default_value: None,
directives: vec![],
});
generated_filter_fields.push(InputValue {
position: Pos::default(),
description: None,
name: "or".to_string(),
value_type: Type::ListType(Box::new(Type::NamedType(
filter_type_name.to_owned(),
))),
default_value: None,
directives: vec![],
});
}

let typedef = TypeDefinition::InputObject(InputObjectType {
position: Pos::default(),
Expand Down
24 changes: 22 additions & 2 deletions graphql/src/store/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,28 @@ fn build_filter_from_object(
let (field_name, op) = sast::parse_field_as_filter(key);

Ok(match op {
And => EntityFilter::And(build_list_filter_from_object(entity, object, schema)?),
Or => EntityFilter::Or(build_list_filter_from_object(entity, object, schema)?),
And => {
if ENV_VARS.graphql.disable_bool_filters {
return Err(QueryExecutionError::NotSupported(
"Boolean filters are not supported".to_string(),
));
}

return Ok(EntityFilter::And(build_list_filter_from_object(
entity, object, schema,
)?));
}
Or => {
if ENV_VARS.graphql.disable_bool_filters {
return Err(QueryExecutionError::NotSupported(
"Boolean filters are not supported".to_string(),
));
}

return Ok(EntityFilter::Or(build_list_filter_from_object(
entity, object, schema,
)?));
}
Child => match value {
DataValue::Object(obj) => {
build_child_filter_from_object(entity, field_name, obj, schema)?
Expand Down

0 comments on commit 9bc891a

Please sign in to comment.