Skip to content

Commit 528d6ae

Browse files
committed
graphql: Change the default for running validations
Set ENABLE_GRAPHQL_VALIDATIONS to any value in the environment to enable validations, rather than enabling them by default and disabling them on demand
1 parent 081480a commit 528d6ae

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

core/tests/interfaces.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,20 @@ async fn follow_interface_reference_invalid() {
269269
.await
270270
.unwrap();
271271

272+
// Depending on whether `ENABLE_GRAPHQL_VALIDATIONS` is set or not, we
273+
// get different errors
272274
match &res.to_result().unwrap_err()[0] {
273275
QueryError::ExecutionError(QueryExecutionError::ValidationError(_, error_message)) => {
274276
assert_eq!(
275277
error_message,
276278
"Cannot query field \"parent\" on type \"Legged\"."
277279
);
278280
}
279-
e => panic!("error {} is not the expected one", e),
281+
QueryError::ExecutionError(QueryExecutionError::UnknownField(_, type_name, field_name)) => {
282+
assert_eq!(type_name, "Legged");
283+
assert_eq!(field_name, "parent");
284+
}
285+
e => panic!("error `{}` is not the expected one", e),
280286
}
281287
}
282288

@@ -1370,6 +1376,16 @@ async fn enum_list_filters() {
13701376

13711377
#[tokio::test]
13721378
async fn recursive_fragment() {
1379+
// Depending on whether `ENABLE_GRAPHQL_VALIDATIONS` is set or not, we
1380+
// get different error messages
1381+
const FOO_ERRORS: [&str; 2] = [
1382+
"Cannot spread fragment \"FooFrag\" within itself.",
1383+
"query has fragment cycle including `FooFrag`",
1384+
];
1385+
const FOO_BAR_ERRORS: [&str; 2] = [
1386+
"Cannot spread fragment \"BarFrag\" within itself via \"FooFrag\".",
1387+
"query has fragment cycle including `BarFrag`",
1388+
];
13731389
let subgraph_id = "RecursiveFragment";
13741390
let schema = "
13751391
type Foo @entity {
@@ -1402,7 +1418,7 @@ async fn recursive_fragment() {
14021418
.await
14031419
.unwrap();
14041420
let data = res.to_result().unwrap_err()[0].to_string();
1405-
assert_eq!(data, "Cannot spread fragment \"FooFrag\" within itself.");
1421+
assert!(FOO_ERRORS.contains(&data.as_str()));
14061422

14071423
let co_recursive = "
14081424
query {
@@ -1429,8 +1445,5 @@ async fn recursive_fragment() {
14291445
.await
14301446
.unwrap();
14311447
let data = res.to_result().unwrap_err()[0].to_string();
1432-
assert_eq!(
1433-
data,
1434-
"Cannot spread fragment \"BarFrag\" within itself via \"FooFrag\"."
1435-
);
1448+
assert!(FOO_BAR_ERRORS.contains(&data.as_str()));
14361449
}

graphql/src/execution/query.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ use crate::{execution::get_field, schema::api::ErrorPolicy};
2424

2525
lazy_static! {
2626
static ref GRAPHQL_VALIDATION_PLAN: ValidationPlan = ValidationPlan::from(
27-
if std::env::var("DISABLE_GRAPHQL_VALIDATIONS")
28-
.unwrap_or_else(|_| "false".into())
29-
.parse::<bool>()
30-
.unwrap_or_else(|_| false)
31-
{
27+
if std::env::var("ENABLE_GRAPHQL_VALIDATIONS").ok().is_none() {
3228
vec![]
3329
} else {
3430
vec![

0 commit comments

Comments
 (0)