Skip to content

Commit

Permalink
Minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jan 17, 2024
1 parent d49f5c2 commit ccd1009
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
26 changes: 18 additions & 8 deletions juniper/src/schema/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ impl<'a, S> SchemaType<'a, S> {

/// Get a list of types.
pub fn type_list(&self) -> Vec<TypeType<S>> {
let mut types: Vec<_> = self.types.values().map(|t| TypeType::Concrete(t)).collect();
let mut types = self
.types
.values()
.map(|t| TypeType::Concrete(t))
.collect::<Vec<_>>();
sort_concrete_types(&mut types);
types
}
Expand Down Expand Up @@ -445,7 +449,7 @@ impl<'a, S> SchemaType<'a, S> {

/// Get a list of directives.
pub fn directive_list(&self) -> Vec<&DirectiveType<S>> {
let mut directives: Vec<_> = self.directives.values().collect();
let mut directives = self.directives.values().collect::<Vec<_>>();
sort_directives(&mut directives);
directives
}
Expand Down Expand Up @@ -689,7 +693,7 @@ impl<'a, S> fmt::Display for TypeType<'a, S> {
}
}

/// Sorts the provided [`TypeType`] in the "type-then-name" manner.
/// Sorts the provided [`TypeType`]s in the "type-then-name" manner.
fn sort_concrete_types<S>(types: &mut [TypeType<S>]) {
types.sort_by(|a, b| {
concrete_type_sort::by_type(a)
Expand All @@ -698,7 +702,7 @@ fn sort_concrete_types<S>(types: &mut [TypeType<S>]) {
});
}

/// Sorts the provided [`DirectiveType`] by name.
/// Sorts the provided [`DirectiveType`]s by name.
fn sort_directives<S>(directives: &mut [&DirectiveType<S>]) {
directives.sort_by(|a, b| a.name.cmp(&b.name));
}
Expand All @@ -720,12 +724,12 @@ mod concrete_type_sort {
TypeType::Concrete(MetaType::Scalar(_)) => 3,
TypeType::Concrete(MetaType::Object(_)) => 4,
TypeType::Concrete(MetaType::Union(_)) => 5,
// note: The following types are not part of the introspected types:
// NOTE: The following types are not part of the introspected types.
TypeType::Concrete(
MetaType::List(_) | MetaType::Nullable(_) | MetaType::Placeholder(_),
) => 6,
// note: Other variants will not appear since we're only sorting concrete types:
_ => 7,
// NOTE: Other variants will not appear since we're only sorting concrete types:
TypeType::List(..) | TypeType::NonNull(_) => 7,
}
}

Expand All @@ -738,7 +742,13 @@ mod concrete_type_sort {
TypeType::Concrete(MetaType::Scalar(meta)) => Some(&meta.name),
TypeType::Concrete(MetaType::Object(meta)) => Some(&meta.name),
TypeType::Concrete(MetaType::Union(meta)) => Some(&meta.name),
_ => None,
TypeType::Concrete(
// NOTE: The following types are not part of the introspected types.
MetaType::List(_) | MetaType::Nullable(_) | MetaType::Placeholder(_),
)
// NOTE: Other variants will not appear since we're only sorting concrete types:
| TypeType::List(..)
| TypeType::NonNull(_) => None,
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions juniper/src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
name: ref iface_name,
..
})) => {
let mut type_names: Vec<_> = context
let mut type_names = context
.types
.values()
.filter_map(|ct| {
Expand All @@ -301,13 +301,12 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
None
}
})
.collect();
.collect::<Vec<_>>();
type_names.sort();

Some(
type_names
.into_iter()
.filter_map(|type_name| context.type_by_name(type_name))
.filter_map(|n| context.type_by_name(n))
.collect(),
)
}
Expand Down
1 change: 1 addition & 0 deletions juniper/src/tests/introspection_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ async fn test_builtin_introspection_query() {
);
let result = crate::introspect(&schema, &database, IntrospectionFormat::default()).unwrap();
let expected = schema_introspection_result();

assert_eq!(result, (expected, vec![]));
}

Expand Down

0 comments on commit ccd1009

Please sign in to comment.