Skip to content

Commit 80ce031

Browse files
API docs and stabilization pass (#942)
Co-authored-by: Renée <[email protected]>
1 parent caf7b6f commit 80ce031

File tree

11 files changed

+404
-62
lines changed

11 files changed

+404
-62
lines changed

crates/apollo-compiler/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,28 @@ 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+
24+
- **Move `apollo_compiler::schema::ArgumentByNameError` into `apollo_compiler::ast` - [SimonSapin], [pull/942]**
25+
26+
## Features
27+
28+
- **Overload `DirectiveList::push` to also accept a plain `Directive`, not just `Node<Directive>` - [SimonSapin], [pull/942]**
29+
- **Add `ExtendedType::as_scalar(&self) -> Option<&ScalarType>` and similar - [SimonSapin], [pull/942]**
30+
2231
## Fixes
2332
- **Validate against reserved names starting with `__` in schemas - [SimonSapin], [pull/923].**
2433
- **Fix duplicate diagnostic for variable with invalid default value - [SimonSapin], [pull/925] and [pull/929].**
2534

35+
## Documentation
36+
37+
- **Added or reworded many doc-comments - [SimonSapin], [pull/942]**
38+
2639
[SimonSapin]: https://github.com/SimonSapin
2740
[pull/923]: https://github.com/apollographql/apollo-rs/issues/923
2841
[pull/925]: https://github.com/apollographql/apollo-rs/issues/925
2942
[pull/929]: https://github.com/apollographql/apollo-rs/pull/929
43+
[pull/942]: https://github.com/apollographql/apollo-rs/pull/942
3044

3145

3246
# [1.0.0-beta.24](https://crates.io/crates/apollo-compiler/1.0.0-beta.24) - 2024-09-24

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::*;
22
use crate::name;
33
use crate::parser::Parser;
44
use crate::parser::SourceSpan;
5-
use crate::schema::ArgumentByNameError;
65
use crate::schema::SchemaBuilder;
76
use crate::validation::DiagnosticList;
87
use crate::validation::Valid;
@@ -218,6 +217,8 @@ impl Definition {
218217
}
219218
}
220219

220+
/// If this node was parsed from a source file, returns the file ID and source span
221+
/// (start and end byte offsets) within that file.
221222
pub fn location(&self) -> Option<SourceSpan> {
222223
match self {
223224
Self::OperationDefinition(def) => def.location(),
@@ -242,7 +243,8 @@ impl Definition {
242243

243244
/// Return the name of this type definition or extension.
244245
///
245-
/// Operations may be anonymous, and schema definitions never have a name, in that case this function returns `None`.
246+
/// Operations may be anonymous, and schema definitions and extensions never have a name.
247+
/// In those cases this method returns `None`.
246248
pub fn name(&self) -> Option<&Name> {
247249
match self {
248250
Self::OperationDefinition(def) => def.name.as_ref(),
@@ -554,6 +556,11 @@ impl DirectiveList {
554556
self.get(name).is_some()
555557
}
556558

559+
/// Accepts either [`Node<Directive>`] or [`Directive`].
560+
pub fn push(&mut self, directive: impl Into<Node<Directive>>) {
561+
self.0.push(directive.into());
562+
}
563+
557564
serialize_method!();
558565
}
559566

@@ -620,6 +627,13 @@ impl FromIterator<Directive> for DirectiveList {
620627
}
621628

622629
impl Directive {
630+
pub fn new(name: Name) -> Self {
631+
Self {
632+
name,
633+
arguments: Vec::new(),
634+
}
635+
}
636+
623637
/// Returns the value of the argument named `name`, accounting for nullability
624638
/// and for the default value in `schema`’s directive definition.
625639
pub fn argument_by_name<'doc_or_schema>(
@@ -802,7 +816,9 @@ impl Type {
802816
Type::List(Box::new(self))
803817
}
804818

805-
/// If the type is a list type or a non-null list type, return the item type.
819+
/// If the type is a list type (nullable or not), returns the inner item type.
820+
///
821+
/// Otherwise returns `self` unchanged.
806822
///
807823
/// # Example
808824
/// ```
@@ -832,18 +848,20 @@ impl Type {
832848
matches!(self, Type::NonNullNamed(_) | Type::NonNullList(_))
833849
}
834850

835-
/// Returns whether this type is a list, on a non-null list
851+
/// Returns whether this type is a list type (nullable or not)
836852
pub fn is_list(&self) -> bool {
837853
matches!(self, Type::List(_) | Type::NonNullList(_))
838854
}
839855

856+
/// Returns whether this type is a named type (nullable or not), as opposed to a list type.
840857
pub fn is_named(&self) -> bool {
841858
matches!(self, Type::Named(_) | Type::NonNullNamed(_))
842859
}
843860

844861
/// Can a value of this type be used when the `target` type is expected?
845862
///
846-
/// Implementation of spec function `AreTypesCompatible()`.
863+
/// Implementation of spec function
864+
/// [_AreTypesCompatible()_](https://spec.graphql.org/draft/#AreTypesCompatible()).
847865
pub fn is_assignable_to(&self, target: &Self) -> bool {
848866
match (target, self) {
849867
// Can't assign a nullable type to a non-nullable type.
@@ -894,7 +912,7 @@ impl FieldDefinition {
894912
impl InputValueDefinition {
895913
/// Returns true if usage sites are required to provide a value for this input value.
896914
///
897-
/// That means:
915+
/// An input value is required when:
898916
/// - its type is non-null, and
899917
/// - it does not have a default value
900918
pub fn is_required(&self) -> bool {
@@ -909,6 +927,8 @@ impl EnumValueDefinition {
909927
}
910928

911929
impl Selection {
930+
/// If this node was parsed from a source file, returns the file ID and source span
931+
/// (start and end byte offsets) within that file.
912932
pub fn location(&self) -> Option<SourceSpan> {
913933
match self {
914934
Self::Field(field) => field.location(),
@@ -945,17 +965,19 @@ impl Selection {
945965
}
946966

947967
impl Field {
948-
/// Get the name that will be used for this field selection in response formatting.
968+
/// Get the name that will be used for this field selection in [response `data`].
949969
///
950-
/// For example, in this operation, the response name is "sourceField":
970+
/// For example, in this operation, the response name is `sourceField`:
951971
/// ```graphql
952972
/// query GetField { sourceField }
953973
/// ```
954974
///
955-
/// But in this operation that uses an alias, the response name is "responseField":
975+
/// But in this operation that uses an alias, the response name is `responseField`:
956976
/// ```graphql
957977
/// query GetField { responseField: sourceField }
958978
/// ```
979+
///
980+
/// [response `data`]: https://spec.graphql.org/draft/#sec-Response-Format
959981
pub fn response_name(&self) -> &Name {
960982
self.alias.as_ref().unwrap_or(&self.name)
961983
}
@@ -1000,6 +1022,9 @@ impl Value {
10001022
}
10011023
}
10021024

1025+
/// Convert a [`FloatValue`] **_or [`IntValue`]_** to floating point representation.
1026+
///
1027+
/// Returns `None` if the value is of a different kind, or if the conversion overflows.
10031028
pub fn to_f64(&self) -> Option<f64> {
10041029
match self {
10051030
Value::Float(value) => value.try_to_f64().ok(),
@@ -1523,6 +1548,7 @@ impl From<InputObjectTypeExtension> for Definition {
15231548
}
15241549
}
15251550

1551+
/// The Rust unit value a.k.a empty tuple converts to [`Value::Null`].
15261552
impl From<()> for Value {
15271553
fn from(_value: ()) -> Self {
15281554
Value::Null
@@ -1565,6 +1591,7 @@ impl From<bool> for Value {
15651591
}
15661592
}
15671593

1594+
/// The Rust unit value a.k.a empty tuple converts to [`Value::Null`].
15681595
impl From<()> for Node<Value> {
15691596
fn from(value: ()) -> Self {
15701597
Node::new(value.into())

0 commit comments

Comments
 (0)