Skip to content

Commit 90d7fb9

Browse files
fix(compiler): InputValueDefinition::is_required() returns false if there is a default value (#798)
* fix(compiler): `InputValueDefinition::is_required()` returns false if there is a default value * changelog
1 parent d535d4e commit 90d7fb9

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

crates/apollo-compiler/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1919

2020
# [x.x.x] (unreleased) - 2024-mm-dd
2121

22+
## BREAKING
23+
- **`InputValueDefinition::is_required()` returns false if it has a default value - [goto-bus-stop], [pull/798]**
24+
Now `argument.is_required() == true` only if the type is non-null and there is no
25+
default value, meaning a value must be provided when it's used.
26+
2227
## Features
2328
- **Implement `fmt::Display` for `ComponentName` - [goto-bus-stop], [pull/795]**
2429

2530
[goto-bus-stop]: https://github.com/goto-bus-stop]
2631
[pull/795]: https://github.com/apollographql/apollo-rs/pull/795
32+
[pull/798]: https://github.com/apollographql/apollo-rs/pull/798
2733

2834
# [1.0.0-beta.11](https://crates.io/crates/apollo-compiler/1.0.0-beta.11) - 2023-12-19
2935

crates/apollo-compiler/src/ast/impls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,13 @@ impl FieldDefinition {
840840
}
841841

842842
impl InputValueDefinition {
843+
/// Returns true if usage sites are required to provide a value for this input value.
844+
///
845+
/// That means:
846+
/// - its type is non-null, and
847+
/// - it does not have a default value
843848
pub fn is_required(&self) -> bool {
844-
matches!(*self.ty, Type::NonNullNamed(_) | Type::NonNullList(_))
849+
self.ty.is_non_null() && self.default_value.is_none()
845850
}
846851

847852
serialize_method!();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub(crate) fn validate_directives<'dir>(
294294
Some(value) => value.is_null(),
295295
};
296296

297-
if arg_def.is_required() && is_null && arg_def.default_value.is_none() {
297+
if arg_def.is_required() && is_null {
298298
diagnostics.push(ValidationError::new(
299299
dir.location(),
300300
DiagnosticData::RequiredArgument {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) fn validate_field(
8787
Some(value) => value.is_null(),
8888
};
8989

90-
if arg_definition.is_required() && is_null && arg_definition.default_value.is_none() {
90+
if arg_definition.is_required() && is_null {
9191
diagnostics.push(ValidationError::new(
9292
field.location(),
9393
DiagnosticData::RequiredArgument {

0 commit comments

Comments
 (0)