Skip to content

Commit e208863

Browse files
authored
fix: metagen select in client_ts (#1011)
<!-- Pull requests are squashed and merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog. --> <!-- 1. Explain WHAT the change is about --> - Fix selection for optional types in metagen <!-- 2. Explain WHY the change cannot be made simpler --> <!-- 3. Explain HOW users should update their code --> #### Migration notes --- - [ ] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for alias selections in the selection system, improving handling of optional and list types. - **Style** - Enhanced debug output for various type structures, including list, object property, optional, and union types, to display more concise and informative information during debugging. - **Chores** - Updated dependencies to enable additional features for improved debugging support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8f26d74 commit e208863

File tree

8 files changed

+22
-7
lines changed

8 files changed

+22
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ lazy_static = "1.5.0" # FIXME: replace with Lazy
9393
crossbeam-channel = "0.5.13"
9494
enum_dispatch = "0.3.13"
9595
tap = "1.0.1"
96-
derive_more = { version = "1", features = ["from"] }
96+
derive_more = { version = "1", features = ["from", "debug"] }
9797
cached = "0.53.1" # FIXME: replace usage with a Lazy Cell + dashmap
9898
garde = "0.20"
9999
paste = "1.0.15"

src/metagen/src/client_ts/selections.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{interlude::*, shared::client::*};
1313
pub enum TsSelection {
1414
Object(Object),
1515
Union(Union),
16+
Alias(TypeKey),
1617
}
1718

1819
#[derive(Debug)]
@@ -105,13 +106,15 @@ impl ManifestEntry for TsSelection {
105106
match self {
106107
TsSelection::Object(obj) => obj.render(dest, page),
107108
TsSelection::Union(union) => union.render(dest, page),
109+
TsSelection::Alias(_) => Ok(()),
108110
}
109111
}
110112

111-
fn get_reference_expr(&self, _page: &ManifestPage<Self>) -> Option<String> {
113+
fn get_reference_expr(&self, page: &ManifestPage<Self>) -> Option<String> {
112114
match self {
113115
TsSelection::Object(obj) => Some(obj.name.clone()),
114116
TsSelection::Union(union) => Some(union.name.clone()),
117+
TsSelection::Alias(key) => page.get_ref(key),
115118
}
116119
}
117120
}
@@ -130,7 +133,13 @@ pub fn manifest_page(tg: &typegraph::Typegraph) -> ManifestPage<TsSelection> {
130133
| Type::Integer(_)
131134
| Type::String(_)
132135
| Type::File(_) => unreachable!("scalars don't get to have selections"),
133-
Type::Optional(_) | Type::List(_) | Type::Function(_) => {}
136+
Type::Optional(ty) => {
137+
map.insert(*key, TsSelection::Alias(ty.item().key()));
138+
}
139+
Type::List(ty) => {
140+
map.insert(*key, TsSelection::Alias(ty.item().key()));
141+
}
142+
Type::Function(_) => {} // TODO
134143
Type::Object(ty) => {
135144
let ty_props = ty.properties();
136145
let mut props = Vec::with_capacity(ty_props.len());

src/typegraph/graph/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ indexmap.workspace = true
1212
paste.workspace = true
1313
color-eyre.workspace = true
1414
tracing.workspace = true
15+
derive_more.workspace = true
1516

1617
[dev-dependencies]
1718
insta.workspace = true

src/typegraph/graph/src/types/list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use crate::conv::dedup::{DupKey, DupKeyGen};
66
use crate::conv::key::TypeKeyEx;
77
use crate::{interlude::*, Arc, Once};
88

9-
#[derive(Debug)]
9+
#[derive(derive_more::Debug)]
1010
pub struct ListType {
1111
pub base: TypeBase,
12+
#[debug("{:?}", item.get().map(|ty| ty.tag()))]
1213
pub(crate) item: Once<Type>,
1314
pub min_items: Option<u32>,
1415
pub max_items: Option<u32>,

src/typegraph/graph/src/types/object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use crate::policies::PolicySpec;
99
use crate::{interlude::*, TypeNodeExt as _};
1010
use indexmap::IndexMap;
1111

12-
#[derive(Debug)]
12+
#[derive(derive_more::Debug)]
1313
pub struct ObjectProperty {
14+
#[debug("{}", ty.tag())]
1415
pub ty: Type,
1516
pub policies: Vec<PolicySpec>,
1617
pub injection: Option<Arc<InjectionNode>>,

src/typegraph/graph/src/types/optional.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::conv::key::TypeKeyEx;
77
use crate::{interlude::*, TypeNodeExt as _};
88
use crate::{Arc, Once};
99

10-
#[derive(Debug)]
10+
#[derive(derive_more::Debug)]
1111
pub struct OptionalType {
1212
pub base: TypeBase,
13+
#[debug("{}", item.get().map(|ty| ty.tag()).unwrap_or("<unset>"))]
1314
pub(crate) item: Once<Type>,
1415
pub default_value: Option<serde_json::Value>,
1516
}

src/typegraph/graph/src/types/union.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::conv::key::TypeKeyEx;
77
use crate::{interlude::*, TypeNodeExt as _};
88
use crate::{Arc, Once};
99

10-
#[derive(Debug)]
10+
#[derive(derive_more::Debug)]
1111
pub struct UnionType {
1212
pub base: TypeBase,
13+
#[debug("{:?}", variants.get().map(|i| i.iter().map(|v| v.tag()).collect::<Vec<_>>()))]
1314
pub(crate) variants: Once<Vec<Type>>,
1415
pub either: bool,
1516
}

0 commit comments

Comments
 (0)