Skip to content

Commit 18b6ada

Browse files
committed
Polishing, vol.4
1 parent b62e0d4 commit 18b6ada

File tree

7 files changed

+59
-41
lines changed

7 files changed

+59
-41
lines changed

juniper/CHANGELOG.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,38 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
3232
- Renamed `ObjectId` scalar to `ObjectID` in types: ([#1277])
3333
- `bson::oid::ObjectId`.
3434
- Optimized schema implementation with [`arcstr` crate]: ([#1247], [#819])
35-
- Removed lifetime parameters from `MetaType` and its members.
36-
- Made `MetaType::name()`, `MetaType::description()` and `MetaType::specified_by_url()` returning `ArcStr`.
37-
- Made `DeprecationStatus::reason()` returning `ArcStr`.
38-
- Removed lifetime parameters from `DirectiveType`.
39-
- Made `DirectiveType::name` and `DirectiveType::description` using `ArcStr`.
40-
- Removed lifetime parameter from `SchemaType` and `Registry`.
41-
- Made `types::Name` and `types::NameParseError` using `ArcStr` instead of `String`.
42-
- Replaced `FromStr` impl of `types::Name` with `types::Name::new()` constructor.
43-
- Made `GraphQLType::name()` and `GraphQLValue::type_name()` returning `ArcStr`.
44-
- Removed lifetime parameters from `RootNode`.
45-
- Removed lifetime parameters from `ast::Type` and made it generic over string type.
35+
- `ast::Type`:
36+
- Removed lifetime parameters.
37+
- Made it generic over string type.
38+
- `MetaType`:
39+
- Removed lifetime parameters.
40+
- Made `name()`, `description()` and `specified_by_url()` methods returning `ArcStr`.
41+
- `EnumMeta`, `InputObjectMeta`, `InterfaceMeta`, `ListMeta`, `NullableMeta`, `ObjectMeta`, `PlaceholderMeta`, `ScalarMeta` and `UnionMeta`:
42+
- Removed lifetime parameters.
43+
- `meta::Field` and `meta::Argument`:
44+
- Removed lifetime parameters.
45+
- `meta::EnumValue`:
46+
- Made `name` and `description` fields using `ArcStr`.
47+
- `DeprecationStatus`:
48+
- Made `Deprecated` variant using `ArcStr`.
49+
- Made `reason()` method returning `ArcStr`.
50+
- `DirectiveType`:
51+
- Removed lifetime parameters.
52+
- Made `name` and `description` fields using `ArcStr`.
53+
- `SchemaType`:
54+
- Removed lifetime parameters.
55+
- Made `is_subtype()` method accepting `DynType` instead of `Type`.
56+
- `RootNode`:
57+
- Removed lifetime parameters.
58+
- `Registry`:
59+
- Removed lifetime parameters.
60+
- `types::Name` and `types::NameParseError`:
61+
- Made fields using `ArcStr` instead of `String`.
62+
- Replaced `FromStr` impl of `types::Name` with `new()` constructor.
63+
- `GraphQLType`:
64+
- Made `name()` method returning `ArcStr`.
65+
- `GraphQLValue`:
66+
- Made `type_name()` method returning `ArcStr`.
4667

4768
### Added
4869

juniper/src/schema/meta.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
pub enum DeprecationStatus {
1919
/// The field/variant is not deprecated.
2020
Current,
21+
2122
/// The field/variant is deprecated, with an optional reason
2223
Deprecated(Option<ArcStr>),
2324
}

juniper/src/schema/model.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ impl<S> SchemaType<S> {
299299
}
300300

301301
/// Add a description.
302-
pub fn set_description(&mut self, description: ArcStr) {
303-
self.description = Some(description);
302+
pub fn set_description(&mut self, description: impl Into<ArcStr>) {
303+
self.description = Some(description.into());
304304
}
305305

306306
/// Add a directive like `skip` or `include`.
@@ -309,16 +309,16 @@ impl<S> SchemaType<S> {
309309
}
310310

311311
/// Get a type by name.
312-
pub fn type_by_name(&self, name: &str) -> Option<TypeType<S>> {
313-
self.types.get(name).map(|t| TypeType::Concrete(t))
312+
pub fn type_by_name(&self, name: impl AsRef<str>) -> Option<TypeType<S>> {
313+
self.types.get(name.as_ref()).map(|t| TypeType::Concrete(t))
314314
}
315315

316316
/// Get a concrete type by name.
317-
pub fn concrete_type_by_name(&self, name: &str) -> Option<&MetaType<S>> {
318-
self.types.get(name)
317+
pub fn concrete_type_by_name(&self, name: impl AsRef<str>) -> Option<&MetaType<S>> {
318+
self.types.get(name.as_ref())
319319
}
320320

321-
pub(crate) fn lookup_type<N: AsRef<str>>(&self, tpe: &Type<N>) -> Option<&MetaType<S>> {
321+
pub(crate) fn lookup_type(&self, tpe: &Type<impl AsRef<str>>) -> Option<&MetaType<S>> {
322322
match tpe {
323323
Type::Named(name) | Type::NonNullNamed(name) => {
324324
self.concrete_type_by_name(name.as_ref())
@@ -745,15 +745,14 @@ mod concrete_type_sort {
745745
}
746746
}
747747

748-
/// Allows seeing [Type] with different name/string representations
749-
/// as the same type without allocating.
750-
//
751-
// TODO: Ideally this type should not exist, but the reason it currently does
752-
// is that [Type] has a recursive design to allow arbitrary number of list wrappings.
753-
// The list layout could instead be modelled as a modifier so that type becomes a tuple of (name, modifier).
754-
//
755-
// If [Type] is modelled like this it becomes easier to project it as a borrowed version of itself,
756-
// i.e. [Type<ArcStr>] vs [Type<&str>].
748+
/// Allows seeing [`Type`] with different name/string representations
749+
/// as the same type without allocation.
750+
// TODO: Ideally this type should not exist, but the reason it currently does is that `Type` has a
751+
// recursive design to allow arbitrary number of list wrappings.
752+
// The list layout could instead be modelled as a modifier so that type becomes a tuple of
753+
// (name, modifier).
754+
// If `Type` is modelled like this it becomes easier to project it as a borrowed version of
755+
// itself, i.e. [Type<ArcStr>] vs [Type<&str>].
757756
#[derive(Clone, Copy, Debug)]
758757
pub enum DynType<'a> {
759758
Named(&'a str),
@@ -765,12 +764,12 @@ pub enum DynType<'a> {
765764
impl<'a> DynType<'a> {
766765
pub fn equals(&self, other: &DynType) -> bool {
767766
match (self, other) {
768-
(DynType::Named(n0), DynType::Named(n1)) => n0 == n1,
769-
(DynType::List(t0, s0), DynType::List(t1, s1)) => {
767+
(Self::Named(n0), DynType::Named(n1)) => n0 == n1,
768+
(Self::List(t0, s0), DynType::List(t1, s1)) => {
770769
t0.as_dyn_type().equals(&t1.as_dyn_type()) && s0 == s1
771770
}
772-
(DynType::NonNullNamed(n0), DynType::NonNullNamed(n1)) => n0 == n1,
773-
(DynType::NonNullList(t0, s0), DynType::NonNullList(t1, s1)) => {
771+
(Self::NonNullNamed(n0), DynType::NonNullNamed(n1)) => n0 == n1,
772+
(Self::NonNullList(t0, s0), DynType::NonNullList(t1, s1)) => {
774773
t0.as_dyn_type().equals(&t1.as_dyn_type()) && s0 == s1
775774
}
776775
_ => false,
@@ -796,11 +795,11 @@ impl fmt::Display for DynType<'_> {
796795
}
797796
}
798797

799-
/// Trait for converting a [Type] into [DynType]
798+
/// Conversion of a [`Type`] into a [`DynType`].
800799
pub trait AsDynType: fmt::Debug {
801-
/// Project [self] as a [DynType].
800+
/// Project this value as a [`DynType`].
802801
///
803-
/// this function should not allocate memory.
802+
/// Should not allocate memory.
804803
fn as_dyn_type(&self) -> DynType<'_>;
805804
}
806805

juniper/src/schema/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
313313
interface_names
314314
.iter()
315315
.any(|iname| iname == iface_name)
316-
.then(|| name.as_ref())
316+
.then_some(name)
317317
} else {
318318
None
319319
}

juniper/src/types/async_await.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ where
203203
.concrete_type_by_name(
204204
instance
205205
.type_name(info)
206-
.expect("Resolving named type's selection set")
207-
.as_ref(),
206+
.expect("Resolving named type's selection set"),
208207
)
209208
.expect("Type not found in schema");
210209

juniper/src/types/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ where
425425
.concrete_type_by_name(
426426
instance
427427
.type_name(info)
428-
.expect("Resolving named type's selection set")
429-
.as_ref(),
428+
.expect("Resolving named type's selection set"),
430429
)
431430
.expect("Type not found in schema");
432431

juniper/src/types/subscriptions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ where
274274
.concrete_type_by_name(
275275
instance
276276
.type_name(info)
277-
.expect("Resolving named type's selection set")
278-
.as_ref(),
277+
.expect("Resolving named type's selection set"),
279278
)
280279
.expect("Type not found in schema");
281280

0 commit comments

Comments
 (0)