Skip to content

Commit 5923c27

Browse files
committed
Revert default value validation of input fields and arguments
This turns out to break enough existing schemas (Router rejects them as invalid where it previously accepted them) that we consider it a breaking change. See #928
1 parent 973254d commit 5923c27

File tree

3 files changed

+19
-36
lines changed

3 files changed

+19
-36
lines changed

crates/apollo-compiler/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2121

2222
## Fixes
2323
- **Validate against reserved names starting with `__` in schemas - [SimonSapin], [pull/923].**
24-
- **Validate the default value of input fields and arguments - [SimonSapin], [pull/925].**
24+
- **Fix duplicate diagnostic for variable with invalid default value - [SimonSapin], [pull/925].**
2525

2626
[SimonSapin]: https://github.com/SimonSapin
2727
[pull/923]: https://github.com/apollographql/apollo-rs/issues/923

crates/apollo-compiler/src/validation/input_object.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::collections::HashMap;
33
use crate::schema::validation::BuiltInScalars;
44
use crate::schema::InputObjectType;
55
use crate::validation::diagnostics::DiagnosticData;
6-
use crate::validation::value::value_of_correct_type;
76
use crate::validation::CycleError;
87
use crate::validation::DiagnosticList;
98
use crate::validation::RecursionGuard;
@@ -209,10 +208,13 @@ pub(crate) fn validate_input_value_definitions(
209208
},
210209
);
211210
}
212-
if let Some(default) = &input_value.default_value {
213-
let var_defs = &[];
214-
value_of_correct_type(diagnostics, schema, &input_value.ty, default, var_defs);
215-
}
211+
// TODO: Validate default values in apollo-compiler 2.0
212+
// https://github.com/apollographql/apollo-rs/issues/928
213+
//
214+
// if let Some(default) = &input_value.default_value {
215+
// let var_defs = &[];
216+
// value_of_correct_type(diagnostics, schema, &input_value.ty, default, var_defs);
217+
// }
216218
} else if is_built_in {
217219
// `validate_schema()` will insert the missing definition
218220
} else {

crates/apollo-compiler/tests/validation/variable.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,6 @@ fn variables_in_const_contexts() {
354354
);
355355
let errors = schema.validate().unwrap_err().errors;
356356
let expected = expect_test::expect![[r#"
357-
Error: variable `$x` is not defined
358-
╭─[input.graphql:3:34]
359-
360-
3 │ arg: InputObj = {x: ["x"]} @dir2(arg: "x")
361-
│ ─┬─
362-
│ ╰─── not found in this scope
363-
───╯
364357
Error: variable `$x` is not defined
365358
╭─[input.graphql:3:51]
366359
@@ -403,13 +396,6 @@ fn variables_in_const_contexts() {
403396
│ ─┬─
404397
│ ╰─── not found in this scope
405398
────╯
406-
Error: variable `$x` is not defined
407-
╭─[input.graphql:43:39]
408-
409-
43 │ arg2: InputObj = {x: ["x"]} @dir(arg: {x: ["x"]})
410-
│ ─┬─
411-
│ ╰─── not found in this scope
412-
────╯
413399
Error: variable `$x` is not defined
414400
╭─[input.graphql:43:60]
415401
@@ -438,13 +424,6 @@ fn variables_in_const_contexts() {
438424
│ ─┬─
439425
│ ╰─── not found in this scope
440426
────╯
441-
Error: variable `$x` is not defined
442-
╭─[input.graphql:51:39]
443-
444-
51 │ arg2: InputObj = {x: ["x"]} @dir(arg: {x: ["x"]})
445-
│ ─┬─
446-
│ ╰─── not found in this scope
447-
────╯
448427
Error: variable `$x` is not defined
449428
╭─[input.graphql:51:60]
450429
@@ -515,13 +494,6 @@ fn variables_in_const_contexts() {
515494
│ ─┬─
516495
│ ╰─── not found in this scope
517496
────╯
518-
Error: variable `$x` is not defined
519-
╭─[input.graphql:66:28]
520-
521-
66 │ x: [String] = ["x"] @dir2(arg: "x")
522-
│ ─┬─
523-
│ ╰─── not found in this scope
524-
────╯
525497
Error: variable `$x` is not defined
526498
╭─[input.graphql:66:44]
527499
@@ -538,10 +510,19 @@ fn variables_in_const_contexts() {
538510
────╯
539511
"#]];
540512
expected.assert_eq(&errors.to_string());
541-
let expected_schema_errors = 26;
513+
let expected_schema_errors = 22;
542514
assert_eq!(errors.len(), expected_schema_errors);
515+
516+
// Default values not validated yet: https://github.com/apollographql/apollo-rs/issues/928
517+
// * @dir(arg:)
518+
// * Query.field(arg2:)
519+
// * Inter.field(arg2:)
520+
// * InputObj.x
521+
let input_default_values_not_yet_validated = 4;
543522
assert_eq!(
544523
input.matches("\"x\"").count(),
545-
expected_schema_errors + expected_executable_errors
524+
expected_schema_errors
525+
+ expected_executable_errors
526+
+ input_default_values_not_yet_validated
546527
)
547528
}

0 commit comments

Comments
 (0)