Skip to content

Commit 7910ff1

Browse files
committed
Add GRAPH_GRAPHQL_DISABLE_CHILD_SORTING (false by default)
1 parent 115729f commit 7910ff1

File tree

4 files changed

+68
-40
lines changed

4 files changed

+68
-40
lines changed

docs/environment-variables.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ those.
126126
- `GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS`: disables the ability to use AND/OR
127127
filters. This is useful if we want to disable filters because of
128128
performance reasons.
129+
- `GRAPH_GRAPHQL_DISABLE_CHILD_SORTING`: disables the ability to use child-based
130+
sorting. This is useful if we want to disable child-based sorting because of
131+
performance reasons.
129132
- `GRAPH_GRAPHQL_TRACE_TOKEN`: the token to use to enable query tracing for
130133
a GraphQL request. If this is set, requests that have a header
131134
`X-GraphTraceQuery` set to this value will include a trace of the SQL

graph/src/env/graphql.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub struct EnvVarsGraphQl {
8787
/// Set by the flag `GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS`. Off by default.
8888
/// Disables AND/OR filters
8989
pub disable_bool_filters: bool,
90+
/// Set by the flag `GRAPH_GRAPHQL_DISABLE_CHILD_SORTING`. Off by default.
91+
/// Disables child-based sorting
92+
pub disable_child_sorting: bool,
9093
/// Set by `GRAPH_GRAPHQL_TRACE_TOKEN`, the token to use to enable query
9194
/// tracing for a GraphQL request. If this is set, requests that have a
9295
/// header `X-GraphTraceQuery` set to this value will include a trace of
@@ -137,6 +140,7 @@ impl From<InnerGraphQl> for EnvVarsGraphQl {
137140
error_result_size: x.error_result_size.0 .0,
138141
max_operations_per_connection: x.max_operations_per_connection,
139142
disable_bool_filters: x.disable_bool_filters.0,
143+
disable_child_sorting: x.disable_child_sorting.0,
140144
query_trace_token: x.query_trace_token,
141145
}
142146
}
@@ -185,6 +189,8 @@ pub struct InnerGraphQl {
185189
max_operations_per_connection: usize,
186190
#[envconfig(from = "GRAPH_GRAPHQL_DISABLE_BOOL_FILTERS", default = "false")]
187191
pub disable_bool_filters: EnvVarBoolean,
192+
#[envconfig(from = "GRAPH_GRAPHQL_DISABLE_CHILD_SORTING", default = "false")]
193+
pub disable_child_sorting: EnvVarBoolean,
188194
#[envconfig(from = "GRAPH_GRAPHQL_TRACE_TOKEN", default = "")]
189195
query_trace_token: String,
190196
}

graphql/src/schema/api.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ fn field_enum_values_from_child_entity(
216216
}
217217
}
218218

219-
let type_name = resolve_supported_type_name(&field.field_type);
219+
let type_name = match ENV_VARS.graphql.disable_child_sorting {
220+
true => None,
221+
false => resolve_supported_type_name(&field.field_type),
222+
};
220223

221224
Ok(match type_name {
222225
Some(name) => {

graphql/src/store/query.rs

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,48 +62,64 @@ pub(crate) fn build_query<'a>(
6262
(Some((attr, value_type, None)), OrderDirection::Descending) => {
6363
EntityOrder::Descending(attr, value_type)
6464
}
65-
(Some((attr, _, Some(child))), OrderDirection::Ascending) => match child {
66-
OrderByChild::Object(child) => EntityOrder::ChildAscending(EntityOrderByChild::Object(
67-
EntityOrderByChildInfo {
68-
sort_by_attribute: attr,
69-
join_attribute: child.join_attribute,
70-
derived: child.derived,
71-
},
72-
child.entity_type,
73-
)),
74-
OrderByChild::Interface(child) => {
75-
EntityOrder::ChildAscending(EntityOrderByChild::Interface(
76-
EntityOrderByChildInfo {
77-
sort_by_attribute: attr,
78-
join_attribute: child.join_attribute,
79-
derived: child.derived,
80-
},
81-
child.entity_types,
82-
))
65+
(Some((attr, _, Some(child))), OrderDirection::Ascending) => {
66+
if ENV_VARS.graphql.disable_child_sorting {
67+
return Err(QueryExecutionError::NotSupported(
68+
"Sorting by child attributes is not supported".to_string(),
69+
));
8370
}
84-
},
85-
(Some((attr, _, Some(child))), OrderDirection::Descending) => match child {
86-
OrderByChild::Object(child) => {
87-
EntityOrder::ChildDescending(EntityOrderByChild::Object(
88-
EntityOrderByChildInfo {
89-
sort_by_attribute: attr,
90-
join_attribute: child.join_attribute,
91-
derived: child.derived,
92-
},
93-
child.entity_type,
94-
))
71+
match child {
72+
OrderByChild::Object(child) => {
73+
EntityOrder::ChildAscending(EntityOrderByChild::Object(
74+
EntityOrderByChildInfo {
75+
sort_by_attribute: attr,
76+
join_attribute: child.join_attribute,
77+
derived: child.derived,
78+
},
79+
child.entity_type,
80+
))
81+
}
82+
OrderByChild::Interface(child) => {
83+
EntityOrder::ChildAscending(EntityOrderByChild::Interface(
84+
EntityOrderByChildInfo {
85+
sort_by_attribute: attr,
86+
join_attribute: child.join_attribute,
87+
derived: child.derived,
88+
},
89+
child.entity_types,
90+
))
91+
}
92+
}
93+
}
94+
(Some((attr, _, Some(child))), OrderDirection::Descending) => {
95+
if ENV_VARS.graphql.disable_child_sorting {
96+
return Err(QueryExecutionError::NotSupported(
97+
"Sorting by child attributes is not supported".to_string(),
98+
));
9599
}
96-
OrderByChild::Interface(child) => {
97-
EntityOrder::ChildDescending(EntityOrderByChild::Interface(
98-
EntityOrderByChildInfo {
99-
sort_by_attribute: attr,
100-
join_attribute: child.join_attribute,
101-
derived: child.derived,
102-
},
103-
child.entity_types,
104-
))
100+
match child {
101+
OrderByChild::Object(child) => {
102+
EntityOrder::ChildDescending(EntityOrderByChild::Object(
103+
EntityOrderByChildInfo {
104+
sort_by_attribute: attr,
105+
join_attribute: child.join_attribute,
106+
derived: child.derived,
107+
},
108+
child.entity_type,
109+
))
110+
}
111+
OrderByChild::Interface(child) => {
112+
EntityOrder::ChildDescending(EntityOrderByChild::Interface(
113+
EntityOrderByChildInfo {
114+
sort_by_attribute: attr,
115+
join_attribute: child.join_attribute,
116+
derived: child.derived,
117+
},
118+
child.entity_types,
119+
))
120+
}
105121
}
106-
},
122+
}
107123
(None, _) => EntityOrder::Default,
108124
};
109125
query = query.order(order);

0 commit comments

Comments
 (0)