Skip to content

Commit

Permalink
fix: update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-0acf4 committed Jan 8, 2025
1 parent 18bc3cc commit 784e8e1
Show file tree
Hide file tree
Showing 25 changed files with 557 additions and 548 deletions.
16 changes: 8 additions & 8 deletions examples/typegraphs/metagen/rs/fdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Router {
}

pub fn init(&self, args: InitArgs) -> Result<InitResponse, InitError> {
static MT_VERSION: &str = "0.5.0-rc.8";
static MT_VERSION: &str = "0.5.0-rc.9";
if args.metatype_version != MT_VERSION {
return Err(InitError::VersionMismatch(MT_VERSION.into()));
}
Expand Down Expand Up @@ -219,17 +219,17 @@ macro_rules! init_mat {
// gen-static-end
use types::*;
pub mod types {
pub type Idv3TitleString = String;
pub type Idv3ReleaseTimeStringDatetime = String;
pub type Idv3Mp3UrlStringUri = String;
pub type ScalarString1 = String;
pub type ScalarStringDatetime1 = String;
pub type ScalarStringUri1 = String;
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Idv3 {
pub title: Idv3TitleString,
pub artist: Idv3TitleString,
pub title: ScalarString1,
pub artist: ScalarString1,
#[serde(rename = "releaseTime")]
pub release_time: Idv3ReleaseTimeStringDatetime,
pub release_time: ScalarStringDatetime1,
#[serde(rename = "mp3Url")]
pub mp3_url: Idv3Mp3UrlStringUri,
pub mp3_url: ScalarStringUri1,
}
}
pub mod stubs {
Expand Down
8 changes: 4 additions & 4 deletions src/typegate/src/typegraphs/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"type": "string",
"title": "root___type_fn_input_name_string"
"title": "scalar_string_1"
},
{
"type": "optional",
Expand Down Expand Up @@ -99,7 +99,7 @@
},
{
"type": "optional",
"title": "type_name_root___type_fn_input_name_string_optional",
"title": "type_name_scalar_string_1_optional",
"item": 3,
"default_value": null
},
Expand Down Expand Up @@ -127,13 +127,13 @@
},
{
"type": "optional",
"title": "type_fields_fn_input_includeDeprecated_type_fields_fn_input_includeDeprecated_boolean_optional",
"title": "type_fields_fn_input_includeDeprecated_scalar_boolean_1_optional",
"item": 11,
"default_value": null
},
{
"type": "boolean",
"title": "type_fields_fn_input_includeDeprecated_boolean"
"title": "scalar_boolean_1"
},
{
"type": "optional",
Expand Down
36 changes: 18 additions & 18 deletions src/typegate/src/typegraphs/typegate.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
{
"type": "object",
"title": "root_typegraphs_fn_input",
"title": "scalar_struct_shared_1",
"properties": {},
"id": [],
"required": []
Expand All @@ -109,11 +109,11 @@
},
{
"type": "string",
"title": "Typegraph_name_string"
"title": "scalar_string_1"
},
{
"type": "string",
"title": "Typegraph_url_string_uri",
"title": "scalar_string_uri_1",
"format": "uri"
},
{
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"type": "string",
"title": "root_addTypegraph_fn_input_fromString_string_json",
"title": "scalar_string_json_1",
"format": "json"
},
{
Expand Down Expand Up @@ -240,7 +240,7 @@
},
{
"type": "string",
"title": "root_addTypegraph_fn_output_messages_struct_type_string_enum",
"title": "scalar_string_enum_1",
"enum": [
"\"info\"",
"\"warning\"",
Expand Down Expand Up @@ -268,7 +268,7 @@
},
{
"type": "optional",
"title": "root_addTypegraph_fn_output_failure_root_addTypegraph_fn_input_fromString_string_json_optional",
"title": "root_addTypegraph_fn_output_failure_scalar_string_json_1_optional",
"item": 14,
"default_value": null
},
Expand Down Expand Up @@ -296,12 +296,12 @@
},
{
"type": "list",
"title": "root_removeTypegraphs_fn_input_names_Typegraph_name_string_list",
"title": "scalar_scalar_string_1_list_shared_1",
"items": 5
},
{
"type": "boolean",
"title": "root_removeTypegraphs_fn_output"
"title": "scalar_boolean_1"
},
{
"type": "function",
Expand Down Expand Up @@ -333,7 +333,7 @@
},
{
"type": "list",
"title": "root_argInfoByPath_fn_input_argPaths_root_removeTypegraphs_fn_input_names_Typegraph_name_string_list_list",
"title": "root_argInfoByPath_fn_input_argPaths_scalar_scalar_string_1_list_shared_1_list",
"items": 24
},
{
Expand Down Expand Up @@ -369,18 +369,18 @@
},
{
"type": "optional",
"title": "TypeInfo_enum_TypeInfo_enum_root_addTypegraph_fn_input_fromString_string_json_list_optional",
"title": "TypeInfo_enum_TypeInfo_enum_scalar_string_json_1_list_optional",
"item": 32,
"default_value": null
},
{
"type": "list",
"title": "TypeInfo_enum_root_addTypegraph_fn_input_fromString_string_json_list",
"title": "TypeInfo_enum_scalar_string_json_1_list",
"items": 14
},
{
"type": "optional",
"title": "TypeInfo_format_Typegraph_name_string_optional",
"title": "TypeInfo_format_scalar_string_1_optional",
"item": 5,
"default_value": null
},
Expand Down Expand Up @@ -440,7 +440,7 @@
},
{
"type": "object",
"title": "root_findAvailableOperations_fn_input",
"title": "scalar_struct_shared_2",
"properties": {
"typegraph": 5
},
Expand Down Expand Up @@ -477,7 +477,7 @@
},
{
"type": "string",
"title": "OperationInfo_type_string_enum",
"title": "scalar_string_enum_2",
"enum": [
"\"query\"",
"\"mutation\""
Expand Down Expand Up @@ -596,7 +596,7 @@
},
{
"type": "object",
"title": "root_execRawPrismaRead_fn_input",
"title": "scalar_struct_shared_3",
"properties": {
"typegraph": 5,
"runtime": 5,
Expand Down Expand Up @@ -697,13 +697,13 @@
},
{
"type": "optional",
"title": "PrismaBatchQuery_transaction_struct_isolationLevel_PrismaBatchQuery_transaction_struct_isolationLevel_string_enum_optional",
"title": "PrismaBatchQuery_transaction_struct_isolationLevel_scalar_string_enum_3_optional",
"item": 63,
"default_value": null
},
{
"type": "string",
"title": "PrismaBatchQuery_transaction_struct_isolationLevel_string_enum",
"title": "scalar_string_enum_3",
"enum": [
"\"read uncommitted\"",
"\"readuncommitted\"",
Expand Down Expand Up @@ -777,7 +777,7 @@
},
{
"type": "integer",
"title": "root_queryPrismaModel_fn_input_offset_integer"
"title": "scalar_integer_1"
},
{
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ expression: typegraph.0
},
{
"type": "integer",
"title": "root_one_fn_input_one_integer"
"title": "scalar_integer_1"
},
{
"type": "integer",
"title": "root_one_fn_input_two_integer",
"title": "scalar_integer_2",
"minimum": 12,
"maximum": 44
},
{
"type": "optional",
"title": "root_one_fn_input_three_root_one_fn_input_three_root_one_fn_input_three_float_list_optional",
"title": "root_one_fn_input_three_root_one_fn_input_three_scalar_float_1_list_optional",
"item": 6,
"default_value": null
},
{
"type": "list",
"title": "root_one_fn_input_three_root_one_fn_input_three_float_list",
"title": "root_one_fn_input_three_scalar_float_1_list",
"items": 7
},
{
"type": "float",
"title": "root_one_fn_input_three_float"
"title": "scalar_float_1"
}
],
"materializers": [
Expand Down
51 changes: 36 additions & 15 deletions src/typegraph/core/src/utils/postprocess/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl super::PostProcessor for NamingProcessor {
let mut acc = VisitCollector {
named_types: Default::default(),
path: vec![],
// ref related
counts: ref_counters.counts,
name_occurences: Default::default(),
};
for (key, &ty_id) in &root_data.properties {
acc.path.push((
Expand All @@ -71,8 +73,10 @@ struct VisitContext<'a> {
}
struct VisitCollector {
named_types: HashMap<u32, Rc<str>>,
counts: HashMap<u32, IndexSet<u32>>,
path: Vec<(PathSegment, Rc<str>)>,
// ref related
counts: HashMap<u32, IndexSet<u32>>,
name_occurences: HashMap<String, u32>,
}

struct TypeRefCount {
Expand All @@ -98,6 +102,19 @@ impl VisitCollector {

false
}

pub fn next_name(&mut self, name: String) -> String {
// Hopefully more stable than ids on snapshots
format!(
"scalar_{name}_{}",
self.name_occurences
.entry(name.clone())
.and_modify(|counter| {
*counter += 1;
})
.or_insert(1)
)
}
}

fn visit_type(cx: &VisitContext, acc: &mut VisitCollector, id: u32) -> anyhow::Result<Rc<str>> {
Expand Down Expand Up @@ -261,10 +278,12 @@ fn collect_ref_info(
id: u32,
visited: &mut HashSet<u32>,
) -> anyhow::Result<()> {
if !visited.insert(id) {
if cx.user_named.contains(&id) || visited.contains(&id) {
return Ok(());
}

visited.insert(id);

let node = &cx.tg.types[id as usize];
match node {
TypeNode::Boolean { .. }
Expand Down Expand Up @@ -320,16 +339,18 @@ fn gen_name(cx: &VisitContext, acc: &mut VisitCollector, id: u32, ty_name: &str)
let name: Rc<str> = if cx.user_named.contains(&id) {
node.base().title.clone().into()
} else if node.is_scalar() {
format!("scalar_{ty_name}").into()
acc.next_name(ty_name.to_string()).into()
} else {
let use_if_ok = |default: String| {
if acc.has_more_than_one_referrer(id) {
// Cannot be opinionated on the prefix path if shared (confusing)
format!("{ty_name}_shared_t{id}")
} else {
default
}
};
macro_rules! use_if_ok {
($default:expr) => {
if acc.has_more_than_one_referrer(id) {
// Cannot be opinionated on the prefix path if shared (confusing)
acc.next_name(format!("{ty_name}_shared")).into()
} else {
$default
}
};
}

let title;
let mut last = acc.path.len();
Expand All @@ -340,11 +361,11 @@ fn gen_name(cx: &VisitContext, acc: &mut VisitCollector, id: u32, ty_name: &str)
// we don't include optional and list nodes in
// generated names (useless but also, they might be placeholders)
Edge::OptionalItem | Edge::ArrayItem => continue,
Edge::FunctionInput => use_if_ok(format!("{last_name}_input")),
Edge::FunctionOutput => use_if_ok(format!("{last_name}_output")),
Edge::ObjectProp(key) => use_if_ok(format!("{last_name}_{key}_{ty_name}")),
Edge::FunctionInput => use_if_ok!(format!("{last_name}_input")),
Edge::FunctionOutput => use_if_ok!(format!("{last_name}_output")),
Edge::ObjectProp(key) => use_if_ok!(format!("{last_name}_{key}_{ty_name}")),
Edge::EitherVariant(idx) | Edge::UnionVariant(idx) => {
use_if_ok(format!("{last_name}_t{idx}_{ty_name}"))
use_if_ok!(format!("{last_name}_t{idx}_{ty_name}"))
}
};
break;
Expand Down
Loading

0 comments on commit 784e8e1

Please sign in to comment.