Skip to content

Commit 863d118

Browse files
Add convenience methods {Field,Directive}Definition::argument_by_name (#801)
* Add convenience methods `{Field,Directive}Definition::argument_by_name` * chglg
1 parent 1ddc01f commit 863d118

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/apollo-compiler/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2121

2222
## BREAKING
2323
- **`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.
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.
2626

2727
## Features
2828
- **Implement `fmt::Display` for `ComponentName` - [goto-bus-stop], [pull/795]**
29+
- **Add `FieldDefinition::argument_by_name` and `DirectiveDefinition::argument_by_name` - [goto-bus-stop], [pull/FIXME]**
30+
- These methods return an argument definition by name, or `None`.
2931

3032
[goto-bus-stop]: https://github.com/goto-bus-stop]
3133
[pull/795]: https://github.com/apollographql/apollo-rs/pull/795

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ impl FragmentDefinition {
459459
}
460460

461461
impl DirectiveDefinition {
462+
/// Returns the definition of an argument by a given name.
463+
pub fn argument_by_name(&self, name: &str) -> Option<&Node<InputValueDefinition>> {
464+
self.arguments.iter().find(|argument| argument.name == name)
465+
}
466+
462467
serialize_method!();
463468
}
464469

@@ -624,6 +629,7 @@ impl FromIterator<Directive> for DirectiveList {
624629
}
625630

626631
impl Directive {
632+
/// Returns the value provided to the named argument.
627633
pub fn argument_by_name(&self, name: &str) -> Option<&Node<Value>> {
628634
self.arguments
629635
.iter()
@@ -836,6 +842,11 @@ impl Type {
836842
}
837843

838844
impl FieldDefinition {
845+
/// Returns the definition of an argument by a given name.
846+
pub fn argument_by_name(&self, name: &str) -> Option<&Node<InputValueDefinition>> {
847+
self.arguments.iter().find(|argument| argument.name == name)
848+
}
849+
839850
serialize_method!();
840851
}
841852

0 commit comments

Comments
 (0)