diff --git a/deno.lock b/deno.lock index 5f5c0b2d41..4124d6e754 100644 --- a/deno.lock +++ b/deno.lock @@ -9,7 +9,6 @@ "jsr:@std/assert@^1.0.2": "jsr:@std/assert@1.0.4", "jsr:@std/assert@^1.0.4": "jsr:@std/assert@1.0.6", "jsr:@std/assert@^1.0.6": "jsr:@std/assert@1.0.6", - "jsr:@std/async@^1.0.3": "jsr:@std/async@1.0.5", "jsr:@std/bytes@^0.221.0": "jsr:@std/bytes@0.221.0", "jsr:@std/bytes@^1.0.2": "jsr:@std/bytes@1.0.2", "jsr:@std/bytes@^1.0.2-rc.3": "jsr:@std/bytes@1.0.2", @@ -60,7 +59,6 @@ "npm:lodash@4.17.21": "npm:lodash@4.17.21", "npm:mathjs@11.11.1": "npm:mathjs@11.11.1", "npm:multiformats@13.1.0": "npm:multiformats@13.1.0", - "npm:pg@8.12.0": "npm:pg@8.12.0", "npm:validator@13.12.0": "npm:validator@13.12.0", "npm:zod-validation-error@3.3.0": "npm:zod-validation-error@3.3.0_zod@3.23.8", "npm:zod@3.23.8": "npm:zod@3.23.8" @@ -113,9 +111,6 @@ "jsr:@std/internal@^1.0.4" ] }, - "@std/async@1.0.5": { - "integrity": "31d68214bfbb31bd4c6022401d484e3964147c76c9220098baa703a39b6c2da6" - }, "@std/bytes@0.221.0": { "integrity": "64a047011cf833890a4a2ab7293ac55a1b4f5a050624ebc6a0159c357de91966" }, @@ -443,73 +438,6 @@ "integrity": "sha512-HzdtdBwxsIkzpeXzhQ5mAhhuxcHbjEHH+JQoxt7hG/2HGFjjwyolLo7hbaexcnhoEuV4e0TNJ8kkpMjiEYY4VQ==", "dependencies": {} }, - "pg-cloudflare@1.1.1": { - "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==", - "dependencies": {} - }, - "pg-connection-string@2.6.4": { - "integrity": "sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==", - "dependencies": {} - }, - "pg-int8@1.0.1": { - "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", - "dependencies": {} - }, - "pg-pool@3.6.2_pg@8.12.0": { - "integrity": "sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==", - "dependencies": { - "pg": "pg@8.12.0" - } - }, - "pg-protocol@1.6.1": { - "integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==", - "dependencies": {} - }, - "pg-types@2.2.0": { - "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", - "dependencies": { - "pg-int8": "pg-int8@1.0.1", - "postgres-array": "postgres-array@2.0.0", - "postgres-bytea": "postgres-bytea@1.0.0", - "postgres-date": "postgres-date@1.0.7", - "postgres-interval": "postgres-interval@1.2.0" - } - }, - "pg@8.12.0": { - "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", - "dependencies": { - "pg-cloudflare": "pg-cloudflare@1.1.1", - "pg-connection-string": "pg-connection-string@2.6.4", - "pg-pool": "pg-pool@3.6.2_pg@8.12.0", - "pg-protocol": "pg-protocol@1.6.1", - "pg-types": "pg-types@2.2.0", - "pgpass": "pgpass@1.0.5" - } - }, - "pgpass@1.0.5": { - "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", - "dependencies": { - "split2": "split2@4.2.0" - } - }, - "postgres-array@2.0.0": { - "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", - "dependencies": {} - }, - "postgres-bytea@1.0.0": { - "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", - "dependencies": {} - }, - "postgres-date@1.0.7": { - "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", - "dependencies": {} - }, - "postgres-interval@1.2.0": { - "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", - "dependencies": { - "xtend": "xtend@4.0.2" - } - }, "regenerator-runtime@0.14.1": { "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", "dependencies": {} @@ -518,10 +446,6 @@ "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==", "dependencies": {} }, - "split2@4.2.0": { - "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", - "dependencies": {} - }, "tiny-emitter@2.1.0": { "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==", "dependencies": {} @@ -538,10 +462,6 @@ "integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==", "dependencies": {} }, - "xtend@4.0.2": { - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "dependencies": {} - }, "zod-validation-error@3.3.0_zod@3.23.8": { "integrity": "sha512-Syib9oumw1NTqEv4LT0e6U83Td9aVRk9iTXPUQr1otyV1PuXQKOvOwhMNqZIq5hluzHP2pMgnOmHEo7kPdI2mw==", "dependencies": { diff --git a/src/typegraph/core/src/global_store.rs b/src/typegraph/core/src/global_store.rs index 0115b8d803..f46a194e3d 100644 --- a/src/typegraph/core/src/global_store.rs +++ b/src/typegraph/core/src/global_store.rs @@ -6,7 +6,9 @@ use crate::runtimes::{ DenoMaterializer, Materializer, MaterializerData, MaterializerDenoModule, Runtime, }; use crate::types::type_ref::TypeRef; -use crate::types::{NamedTypeRef, Type, TypeDef, TypeDefExt, TypeId, TypeRefBuilder}; +use crate::types::{ + AsTypeDefEx as _, NamedTypeRef, Type, TypeDef, TypeDefExt, TypeId, TypeRefBuilder, +}; use crate::wit::core::{Policy as CorePolicy, PolicyId, RuntimeId}; use crate::wit::utils::Auth as WitAuth; @@ -489,22 +491,22 @@ impl TypeId { as_variant!(List); pub fn is_func(&self) -> Result { - Ok(matches!(self.as_type_def()?, Some(TypeDef::Func(_)))) + Ok(matches!(self.as_xdef()?.type_def, TypeDef::Func(_))) } pub fn resolve_quant(&self) -> Result { let type_id = *self; - match type_id.as_type_def()? { - Some(TypeDef::List(a)) => Ok(a.data.of.into()), - Some(TypeDef::Optional(o)) => Ok(o.data.of.into()), + match type_id.as_xdef()?.type_def { + TypeDef::List(a) => Ok(a.data.of.into()), + TypeDef::Optional(o) => Ok(o.data.of.into()), _ => Ok(type_id), } } pub fn resolve_optional(&self) -> Result { let type_id = *self; - match type_id.as_type_def()? { - Some(TypeDef::Optional(o)) => Ok(o.data.of.into()), + match type_id.as_xdef()?.type_def { + TypeDef::Optional(o) => Ok(o.data.of.into()), _ => Ok(type_id), } } diff --git a/src/typegraph/core/src/params/apply.rs b/src/typegraph/core/src/params/apply.rs index 200aea6d62..e90f31b45a 100644 --- a/src/typegraph/core/src/params/apply.rs +++ b/src/typegraph/core/src/params/apply.rs @@ -150,7 +150,9 @@ pub fn build_transform_data( root_fields: &HashMap, ) -> Result { let mut context = TransformDataBuildContext::default(); - let (new_tree, type_id) = context.check_object_node(resolver_input, root_fields)?; + let (new_tree, type_id) = context + .check_object_node(resolver_input, root_fields) + .context("building apply transform tree")?; let mut query_input_type = t::struct_(); for (name, param) in context.query_params.into_iter() { diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/filters.rs b/src/typegraph/core/src/runtimes/prisma/type_generation/filters.rs index bd23c70df6..25b99b879b 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/filters.rs +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/filters.rs @@ -148,7 +148,7 @@ pub(super) struct ScalarListFilter(pub TypeId); impl TypeGen for ScalarListFilter { fn generate(&self, _context: &PrismaContext) -> Result { - if let Some(TypeDef::Optional(_)) = self.0.as_type_def()? { + if let TypeDef::Optional(_) = self.0.as_xdef()?.type_def { return Err("array of optional not supported".into()); } @@ -251,7 +251,7 @@ impl TypeGen for AvgFilter { .filter_map(|(k, type_id)| { let type_def = type_id.as_xdef().unwrap().type_def; let non_opt_type = match type_def { - TypeDef::Optional(inner) => inner.item().as_type_def().unwrap().unwrap(), + TypeDef::Optional(inner) => inner.item().as_xdef().unwrap().type_def, _ => type_def, }; match non_opt_type { diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap index 211b99b45f..865b5d4fde 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap @@ -21,23 +21,23 @@ root: struct 'Post_query_input' #306 │ │ ├─ [id]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ └─ [name]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [title]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_291' #292 │ └─ item: integer '_skip' #96 ├─ [take]: optional 'optional_289' #290 diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Record inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Record inp.snap index 3e46b02dab..8ccffa757c 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Record inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Record inp.snap @@ -22,24 +22,24 @@ root: struct 'Record_query_input' #114 │ ├─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [created_at]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [name]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_97' #98 │ └─ item: integer '_skip' #96 ├─ [take]: optional 'optional_93' #94 diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap index 61009fc2c3..24ce773079 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap @@ -18,40 +18,40 @@ root: struct 'User_query_input' #217 │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [name]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [posts]: optional '_prisma_sort_by_aggregates' #193 │ └─ item: struct #190 │ ├─ [_avg]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_count]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_max]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_min]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [_sum]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_202' #203 │ └─ item: integer '_skip' #96 ├─ [take]: optional 'optional_200' #201 diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap index d692d18b50..3b5e65e4dd 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap @@ -1639,69 +1639,69 @@ root: struct 'Post_group_by_query_input' #501 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_count]: optional 'optional_420' #421 │ │ └─ item: struct #419 │ │ ├─ [author]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ ├─ [id]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ └─ [title]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_max]: optional 'optional_423' #424 │ │ └─ item: struct #422 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_min]: optional 'optional_423' #424 │ │ └─ item: struct #422 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_sum]: optional 'optional_423' #424 │ │ └─ item: struct #422 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [author]: optional 'optional_431' #432 │ │ └─ item: list 'User_order_by_withoutrel_Post_User' #430 │ │ └─ item: struct #427 │ │ ├─ [id]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ └─ [name]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [title]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_441' #442 │ └─ item: integer '_skip' #104 ├─ [take]: optional 'optional_439' #440 diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Record inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Record inp.snap index b6a39034f7..9a07711a17 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Record inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Record inp.snap @@ -452,77 +452,77 @@ root: struct 'Record_group_by_query_input' #166 │ │ └─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_count]: optional 'optional_86' #87 │ │ └─ item: struct #85 │ │ ├─ [age]: optional '_prisma_sort_nullable' #84 │ │ │ └─ item: union #81 │ │ │ ├─ variant_0: struct #80 -│ │ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ ├─ [created_at]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ ├─ [id]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ └─ [name]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_max]: optional 'optional_89' #90 │ │ └─ item: struct #88 │ │ └─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_min]: optional 'optional_89' #90 │ │ └─ item: struct #88 │ │ └─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_sum]: optional 'optional_89' #90 │ │ └─ item: struct #88 │ │ └─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [age]: optional '_prisma_sort_nullable' #84 │ │ └─ item: union #81 │ │ ├─ variant_0: struct #80 -│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ ├─ [nulls]: string '_prisma_nulls_order' #74 enum{ '"first"', '"last"' } +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [created_at]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [name]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_105' #106 │ └─ item: integer '_skip' #104 ├─ [take]: optional 'optional_101' #102 diff --git a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap index 84a1763337..9a680d2ffd 100644 --- a/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap +++ b/src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap @@ -2306,83 +2306,83 @@ root: struct 'User_group_by_query_input' #350 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_count]: optional 'optional_261' #262 │ │ └─ item: struct #260 │ │ ├─ [id]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ ├─ [name]: optional '_prisma_sort' #79 │ │ │ └─ item: union #76 │ │ │ ├─ variant_0: struct #75 -│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ │ └─ [posts]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_max]: optional 'optional_264' #265 │ │ └─ item: struct #263 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_min]: optional 'optional_264' #265 │ │ └─ item: struct #263 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_sum]: optional 'optional_264' #265 │ │ └─ item: struct #263 │ │ └─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [id]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [name]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [posts]: optional '_prisma_sort_by_aggregates' #271 │ └─ item: struct #268 │ ├─ [_avg]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_count]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_max]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ ├─ [_min]: optional '_prisma_sort' #79 │ │ └─ item: union #76 │ │ ├─ variant_0: struct #75 -│ │ │ └─ [sort]: string '_prisma_sort_order' #72 -│ │ └─ variant_1: string '_prisma_sort_order' #72 +│ │ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ │ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } │ └─ [_sum]: optional '_prisma_sort' #79 │ └─ item: union #76 │ ├─ variant_0: struct #75 -│ │ └─ [sort]: string '_prisma_sort_order' #72 -│ └─ variant_1: string '_prisma_sort_order' #72 +│ │ └─ [sort]: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } +│ └─ variant_1: string '_prisma_sort_order' #72 enum{ '"asc"', '"desc"' } ├─ [skip]: optional 'optional_280' #281 │ └─ item: integer '_skip' #104 ├─ [take]: optional 'optional_278' #279 diff --git a/src/typegraph/core/src/test_utils.rs b/src/typegraph/core/src/test_utils.rs index 11fce422f6..2bfae8cc02 100644 --- a/src/typegraph/core/src/test_utils.rs +++ b/src/typegraph/core/src/test_utils.rs @@ -85,7 +85,7 @@ pub mod tree { use ptree::{print_config::StyleWhen, IndentChars, PrintConfig, Style, TreeItem}; - use crate::types::{FlatTypeRefTarget, Type, TypeDef, TypeDefExt, TypeId}; + use crate::types::{AsTypeDefEx as _, FlatTypeRefTarget, Type, TypeDef, TypeDefExt, TypeId}; pub struct PrintOptions { no_indent_lines: bool, @@ -169,28 +169,28 @@ pub mod tree { } }; - let enum_variants: Option> = - self.type_id - .as_type_def() - .unwrap() - .and_then(|type_def| match type_def { - TypeDef::Integer(typ) => typ - .data - .enumeration - .clone() - .map(|v| v.iter().map(|v| v.to_string()).collect()), - TypeDef::Float(typ) => typ - .data - .enumeration - .clone() - .map(|v| v.iter().map(|v| v.to_string()).collect()), - TypeDef::String(typ) => typ - .data - .enumeration - .clone() - .map(|v| v.iter().map(|v| format!("'{v}'")).collect()), - _ => None, - }); + let enum_variants: Option> = self + .type_id + .as_xdef() + .map(|xdef| match &xdef.type_def { + TypeDef::Integer(typ) => typ + .data + .enumeration + .clone() + .map(|v| v.iter().map(|v| v.to_string()).collect()), + TypeDef::Float(typ) => typ + .data + .enumeration + .clone() + .map(|v| v.iter().map(|v| v.to_string()).collect()), + TypeDef::String(typ) => typ + .data + .enumeration + .clone() + .map(|v| v.iter().map(|v| format!("'{v}'")).collect()), + _ => None, + }) + .unwrap_or(None); let enum_variants = enum_variants .map(|v| format!(" enum{{ {} }}", v.join(", "))) diff --git a/src/typegraph/core/src/typedef/optional.rs b/src/typegraph/core/src/typedef/optional.rs index 662ad64058..77f650838a 100644 --- a/src/typegraph/core/src/typedef/optional.rs +++ b/src/typegraph/core/src/typedef/optional.rs @@ -53,7 +53,11 @@ impl Optional { impl TypeDefData for TypeOptional { fn get_display_params_into(&self, params: &mut Vec) { - params.push(format!("item={}", self.of)); + if let Ok(item_repr) = TypeId(self.of).repr() { + params.push(format!("item={item_repr}")); + } else { + params.push(format!("item=#{}", self.of)); + } if let Some(default) = self.default_item.clone() { params.push(format!("defaultItem={}", default)); } diff --git a/src/typegraph/core/src/types/type_id.rs b/src/typegraph/core/src/types/type_id.rs index e4c1e6231a..5e8289881e 100644 --- a/src/typegraph/core/src/types/type_id.rs +++ b/src/typegraph/core/src/types/type_id.rs @@ -1,7 +1,6 @@ // Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. // SPDX-License-Identifier: MPL-2.0 -use super::{Type, TypeDef}; use crate::errors::Result; use crate::typegraph::TypegraphContext; use crate::types::AsTypeDefEx as _; @@ -51,13 +50,6 @@ impl TypeId { Ok(typ.repr()) } - pub fn as_type_def(&self) -> Result> { - match self.as_type()? { - Type::Ref(_) => Ok(None), - Type::Def(type_def) => Ok(Some(type_def)), - } - } - pub fn hash_child_type( &self, state: &mut crate::conversion::hash::Hasher, diff --git a/src/typegraph/deno/src/typegraph.ts b/src/typegraph/deno/src/typegraph.ts index dd729fff9b..1d7a4fd4e9 100644 --- a/src/typegraph/deno/src/typegraph.ts +++ b/src/typegraph/deno/src/typegraph.ts @@ -223,6 +223,14 @@ export async function typegraph( if (err.payload && !err.cause) { err.cause = err.payload; } + if ("stack" in err.cause) { + console.error(`Error in typegraph '${name}':`); + for (const msg of err.cause.stack) { + console.error(`- ${msg}`); + } + process.exit(1); + } + throw err; } diff --git a/src/typegraph/deno/src/types.ts b/src/typegraph/deno/src/types.ts index c5065f57a2..7a41510d14 100644 --- a/src/typegraph/deno/src/types.ts +++ b/src/typegraph/deno/src/types.ts @@ -40,6 +40,7 @@ import { ApplyFromStatic, InheritDef, } from "./typegraph.ts"; +import { log } from "./io.ts"; export type PolicySpec = | Policy @@ -529,7 +530,7 @@ function serializeApplyParamNode( if (node instanceof ApplyFromArg) { return { source: "arg", name: node.name, typeId: node.type }; } else if (node instanceof ApplyFromStatic) { - return { source: "static", value: JSON.stringify(node.value) }; + return { source: "static", value_json: JSON.stringify(node.value) }; } else if (node instanceof ApplyFromContext) { return { source: "context", key: node.key, typeId: node.type }; } else if (node instanceof ApplyFromSecret) { @@ -626,6 +627,7 @@ export class Func< throw new Error("Invalid apply value: root must be an object"); } const transformTree = JSON.stringify(serialized.fields); + log.info("transform tree", transformTree); const transformData = core.getTransformData(this.inp._id, transformTree); return func( diff --git a/src/typegraph/python/typegraph/graph/metagen.py b/src/typegraph/python/typegraph/graph/metagen.py index c55068bec5..5b819be41f 100644 --- a/src/typegraph/python/typegraph/graph/metagen.py +++ b/src/typegraph/python/typegraph/graph/metagen.py @@ -12,7 +12,7 @@ from typegraph.gen.types import Err from typegraph.graph.shared_types import TypegraphOutput from typegraph.utils import freeze_tg_output -from typegraph.wit import store, wit_utils +from typegraph.wit import ErrorStack, store, wit_utils class Metagen: @@ -60,7 +60,7 @@ def dry_run( fdk_config = self._get_fdk_config(tg_output, target_name) res = wit_utils.metagen_exec(store, fdk_config) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) for item in res.value: if overwrite is not None: item.overwrite = overwrite @@ -75,4 +75,4 @@ def run( items = self.dry_run(tg_output, target_name, overwrite) res = wit_utils.metagen_write_files(store, items, self.workspace_path) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) diff --git a/src/typegraph/python/typegraph/graph/params.py b/src/typegraph/python/typegraph/graph/params.py index a87df8a846..8cc457b5a0 100644 --- a/src/typegraph/python/typegraph/graph/params.py +++ b/src/typegraph/python/typegraph/graph/params.py @@ -5,7 +5,7 @@ import json from typing import List, Optional, TYPE_CHECKING, Any from typegraph.gen.exports import utils -from typegraph.wit import store, wit_utils +from typegraph.wit import ErrorStack, store, wit_utils from typegraph.gen.types import Err @@ -217,7 +217,7 @@ def from_std( res = wit_utils.oauth2(store, service, scopes) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) return cls(res.value) diff --git a/src/typegraph/python/typegraph/graph/tg_deploy.py b/src/typegraph/python/typegraph/graph/tg_deploy.py index d23165492e..b300f46393 100644 --- a/src/typegraph/python/typegraph/graph/tg_deploy.py +++ b/src/typegraph/python/typegraph/graph/tg_deploy.py @@ -13,7 +13,7 @@ from typegraph.graph.shared_types import BasicAuth from typegraph.graph.tg_artifact_upload import ArtifactUploader from typegraph.graph.typegraph import TypegraphOutput -from typegraph.wit import SerializeParams, store, wit_utils +from typegraph.wit import ErrorStack, SerializeParams, store, wit_utils from typegraph import version as sdk_version @@ -112,7 +112,7 @@ def tg_deploy(tg: TypegraphOutput, params: TypegraphDeployParams) -> DeployResul ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) req = request.Request( url=url, @@ -142,7 +142,7 @@ def tg_remove(typegraph_name: str, params: TypegraphRemoveParams): res = wit_utils.gql_remove_query(store, [typegraph_name]) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) req = request.Request( url=url, diff --git a/src/typegraph/python/typegraph/graph/typegraph.py b/src/typegraph/python/typegraph/graph/typegraph.py index 9d41060479..135bb1e6de 100644 --- a/src/typegraph/python/typegraph/graph/typegraph.py +++ b/src/typegraph/python/typegraph/graph/typegraph.py @@ -69,7 +69,7 @@ def __init__( @classmethod def get_active(cls) -> Optional["Typegraph"]: if len(cls._context) == 0: - raise Exception("No active typegraph") + raise ErrorStack("No active typegraph") return cls._context[-1] def __call__(self, **kwargs: ExposeItem): @@ -229,7 +229,19 @@ def serialize(params: SerializeParams): ), ) - builder(Graph(tg)) + try: + builder(Graph(tg)) + except ErrorStack as e: + import sys + + sys.stderr.write(f"Error in typegraph '{actual_name}':\n") + for line in e.stack: + sys.stderr.write("- ") + sys.stderr.write(line) + sys.stderr.write("\n") + sys.exit(1) + except Exception: + raise popped = Typegraph._context.pop() assert tg == popped diff --git a/src/typegraph/python/typegraph/providers/aws.py b/src/typegraph/python/typegraph/providers/aws.py index ef57459f89..2d6030bce9 100644 --- a/src/typegraph/python/typegraph/providers/aws.py +++ b/src/typegraph/python/typegraph/providers/aws.py @@ -13,7 +13,7 @@ from typegraph.gen.exports.runtimes import EffectCreate, EffectRead from typegraph.gen.types import Err from typegraph.runtimes.base import Materializer, Runtime -from typegraph.wit import aws, store +from typegraph.wit import aws, ErrorStack, store class S3Runtime(Runtime): @@ -42,7 +42,7 @@ def __init__( ), ) if isinstance(runtime_id, Err): - raise Exception(runtime_id.value) + raise ErrorStack(runtime_id.value) super().__init__(runtime_id.value) self.host_secret = host_secret @@ -61,7 +61,7 @@ def presign_get(self, bucket: str, expiry_secs: Optional[int] = None): ), ) if isinstance(mat_id, Err): - raise Exception(mat_id.value) + raise ErrorStack(mat_id.value) return t.func( t.struct({"path": t.string()}), @@ -90,7 +90,7 @@ def presign_put( ), ) if isinstance(mat_id, Err): - raise Exception(mat_id.value) + raise ErrorStack(mat_id.value) return t.func( t.struct({"length": t.integer(), "path": t.string()}), @@ -107,7 +107,7 @@ def presign_put( def list(self, bucket: str): mat_id = aws.s3_list(store, self.id, bucket) if isinstance(mat_id, Err): - raise Exception(mat_id.value) + raise ErrorStack(mat_id.value) return t.func( t.struct({"path": t.string().optional()}), @@ -123,7 +123,7 @@ def list(self, bucket: str): def upload(self, bucket: str, file_type: Optional[t.file] = None): mat_id = aws.s3_upload(store, self.id, bucket) if isinstance(mat_id, Err): - raise Exception(mat_id.value) + raise ErrorStack(mat_id.value) if file_type is None: file_type = t.file() @@ -141,7 +141,7 @@ def upload(self, bucket: str, file_type: Optional[t.file] = None): def upload_all(self, bucket: str, file_type: Optional[t.file] = None): mat_id = aws.s3_upload_all(store, self.id, bucket) if isinstance(mat_id, Err): - raise Exception(mat_id.value) + raise ErrorStack(mat_id.value) if file_type is None: file_type = t.file() diff --git a/src/typegraph/python/typegraph/providers/prisma.py b/src/typegraph/python/typegraph/providers/prisma.py index dba914d6b4..80696ccddf 100644 --- a/src/typegraph/python/typegraph/providers/prisma.py +++ b/src/typegraph/python/typegraph/providers/prisma.py @@ -4,7 +4,7 @@ from typing import Union, Optional from typegraph.runtimes.base import Runtime -from typegraph.wit import runtimes, store +from typegraph.wit import ErrorStack, runtimes, store from typegraph.gen.types import Err from typegraph.gen.exports.runtimes import ( Effect, @@ -24,7 +24,7 @@ def __init__(self, name: str, connection_string_secret: str): store, PrismaRuntimeData(name, connection_string_secret) ) if isinstance(runtime_id, Err): - raise Exception(runtime_id.value) + raise ErrorStack(runtime_id.value) super().__init__(runtime_id.value) self.name = name @@ -35,7 +35,7 @@ def find_unique(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_find_unique(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def find_many(self, model: Union[str, t.typedef]) -> t.func: @@ -43,7 +43,7 @@ def find_many(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_find_many(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def find_first(self, model: Union[str, t.typedef]) -> t.func: @@ -51,7 +51,7 @@ def find_first(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_find_first(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def aggregate(self, model: Union[str, t.typedef]) -> t.func: @@ -59,7 +59,7 @@ def aggregate(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_aggregate(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def count(self, model: Union[str, t.typedef]) -> t.func: @@ -67,7 +67,7 @@ def count(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_count(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def group_by(self, model: Union[str, t.typedef]) -> t.func: @@ -75,7 +75,7 @@ def group_by(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_group_by(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def create(self, model: Union[str, t.typedef]) -> t.func: @@ -83,7 +83,7 @@ def create(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_create_one(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def create_many(self, model: Union[str, t.typedef]) -> t.func: @@ -91,7 +91,7 @@ def create_many(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_create_many(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def update(self, model: Union[str, t.typedef]) -> t.func: @@ -99,7 +99,7 @@ def update(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_update_one(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def update_many(self, model: Union[str, t.typedef]) -> t.func: @@ -107,7 +107,7 @@ def update_many(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_update_many(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def upsert(self, model: Union[str, t.typedef]) -> t.func: @@ -115,7 +115,7 @@ def upsert(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_upsert_one(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def delete(self, model: Union[str, t.typedef]) -> t.func: @@ -123,7 +123,7 @@ def delete(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_delete_one(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def delete_many(self, model: Union[str, t.typedef]) -> t.func: @@ -131,13 +131,13 @@ def delete_many(self, model: Union[str, t.typedef]) -> t.func: model = gen_ref(model) type = runtimes.prisma_delete_many(store, self.id, model._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def execute(self, query: str, parameters: t.typedef, effect: Effect) -> t.func: type = runtimes.prisma_execute(store, self.id, query, parameters._id, effect) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def query_raw( @@ -146,7 +146,7 @@ def query_raw( params_id = None if parameters is None else parameters._id type = runtimes.prisma_query_raw(store, self.id, query, params_id, output._id) if isinstance(type, Err): - raise Exception(type.value) + raise ErrorStack(type.value) return t.func.from_type_func(type.value) def link( @@ -185,5 +185,5 @@ def prisma_link( ) if isinstance(type_id, Err): - raise Exception(type_id.value) + raise ErrorStack(type_id.value) return t.typedef(type_id.value) diff --git a/src/typegraph/python/typegraph/t.py b/src/typegraph/python/typegraph/t.py index 71ff9ffa91..5e6215d0cf 100644 --- a/src/typegraph/python/typegraph/t.py +++ b/src/typegraph/python/typegraph/t.py @@ -26,6 +26,7 @@ from typegraph.gen.exports.runtimes import EffectRead from typegraph.gen.types import Err from typegraph.graph.typegraph import ( + ErrorStack, core, store, ApplyFromArg, @@ -69,14 +70,14 @@ def __init__(self, id: int): def __repr__(self): res = core.get_type_repr(store, self._id) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) return res.value def with_policy(self, *policies: Optional[PolicySpec]) -> Self: policy_chain = get_policy_chain(policies) res = core.with_policy(store, self._id, policy_chain) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) ret = copy.copy(self) ret._id = res.value @@ -87,7 +88,7 @@ def rename(self, name: str) -> Self: res = core.rename_type(store, self._id, name) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) ret = copy.copy(self) ret._id = res.value @@ -97,7 +98,7 @@ def rename(self, name: str) -> Self: def _with_injection(self, injection: str) -> Self: res = core.with_injection(store, self._id, injection) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) ret = copy.copy(self) ret._id = res.value @@ -183,18 +184,18 @@ def _with_ext( if as_id: res = core.as_id(store, type_id, as_id == "composite") if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) type_id = res.value config = serialize_config(raw_config) if config: res = core.with_config(store, type_id, config) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) type_id = res.value if name: res = core.rename_type(store, type_id, name) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) type_id = res.value if name == "ExtendedProfile": Log.info(f">>> type#{type_id}; as_id={as_id}; config={config}; name={name}") @@ -236,7 +237,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, as_id, config, name)) self.min = min self.max = max @@ -249,7 +250,7 @@ def __init__( def id(self, as_id: AsId = True) -> "typedef": # "integer" res = core.as_id(store, self._id, as_id == "composite") if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) return typedef(res.value) @@ -290,7 +291,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.min = min self.max = max @@ -306,7 +307,7 @@ def __init__( ): res = core.booleanb(store) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) @@ -343,7 +344,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, as_id, config, name)) self.min = min self.max = max @@ -355,7 +356,7 @@ def __init__( def id(self, as_id: AsId = True) -> "typedef": # "integer" res = core.as_id(store, self._id, as_id == "composite") if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) return typedef(res.value) @@ -433,7 +434,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.min = min @@ -468,7 +469,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.min = min self.max = max @@ -497,7 +498,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.item = item self.default_item = default_item @@ -519,7 +520,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.variants = variants @@ -539,7 +540,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.variants = variants @@ -564,7 +565,9 @@ def __init__( ): if self.__class__ != struct: # custom class if len(self.__class__.__bases__) > 1: - raise Exception("multiple inheritance is currently not supported") + raise ErrorStack.from_str( + "multiple inheritance is currently not supported" + ) (base,) = self.__class__.__bases__ child_cls = self.__class__ child_attr = set([i for i in vars(child_cls) if not i.startswith("__")]) @@ -579,14 +582,14 @@ def __init__( err_msg += " is a reserved field" else: err_msg += " are reserved fields" - raise Exception(err_msg) + raise ErrorStack(err_msg) self_attr = child_attr if base != struct: # child.props should inherit parent.props curr_base = base while curr_base != struct: if len(curr_base.__bases__) > 1: - raise Exception( + raise ErrorStack( "multiple inheritance is currently not supported" ) (curr_base,) = curr_base.__bases__ @@ -615,7 +618,7 @@ def __init__( data, ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) super().__init__(_with_ext(res.value, None, config, name)) self.props = props self.enumeration = enum @@ -652,7 +655,7 @@ def serialize_apply_param_node(node: ApplyParamNode) -> Any: if isinstance(node, (og_list, tuple)): return {"type": "array", "items": [serialize_apply_param_node(v) for v in node]} - raise Exception(f"unexpected node type: node={node}") + raise ErrorStack(f"unexpected node type: node={node}") class func(typedef): @@ -685,7 +688,7 @@ def register(): ) res = core.funcb(store, data) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) return res.value id = register() if type_id is None else type_id @@ -713,7 +716,7 @@ def extend(self, props: Dict[str, typedef]): store, self.out._id, og_list((k, v._id) for k, v in props.items()) ) if isinstance(res, Err): - raise Exception(res.value) + raise ErrorStack(res.value) out = typedef(res.value) @@ -731,7 +734,7 @@ def reduce(self, value: Dict[str, Any]) -> "func": reduced_id = wit_utils.reduceb(store, self._id, reduce_entries) if isinstance(reduced_id, Err): - raise Exception(reduced_id.value) + raise ErrorStack(reduced_id.value) # TODO typedef(...).as_struct() return func( @@ -755,7 +758,7 @@ def apply(self, value: ApplyParamObjectNode) -> "func": import sys print(transform_tree, file=sys.stderr) - raise Exception(transform_data.value) + raise ErrorStack(transform_data.value) return func( typedef(transform_data.value.query_input), diff --git a/src/typegraph/python/typegraph/wit.py b/src/typegraph/python/typegraph/wit.py index 99dcc517ae..83b857f017 100644 --- a/src/typegraph/python/typegraph/wit.py +++ b/src/typegraph/python/typegraph/wit.py @@ -33,3 +33,6 @@ class ErrorStack(Exception): def __init__(self, err: Error): super(ErrorStack, self).__init__("\n".join(f"- {msg}" for msg in err.stack)) self.stack = err.stack + + def from_str(msg: str) -> "ErrorStack": + return ErrorStack(Error([msg])) diff --git a/tests/params/apply.py b/tests/params/apply.py index 3efaee487e..f47e11f1d7 100644 --- a/tests/params/apply.py +++ b/tests/params/apply.py @@ -64,6 +64,23 @@ def apply(g: Graph): "b": g.from_secret("MY_SECRET"), } ), + onOptional=deno.identity( + t.struct( + { + "a": t.struct( + { + "b": t.integer(), + } + ).optional() + } + ) + ).apply( + { + "a": { + "b": g.set(12), + } + } + ), withParent=deno.func( t.struct(), t.struct( diff --git a/tests/runtimes/kv/kv.ts b/tests/runtimes/kv/kv.ts index 1654e6e31b..5425c363a2 100644 --- a/tests/runtimes/kv/kv.ts +++ b/tests/runtimes/kv/kv.ts @@ -4,7 +4,7 @@ import { Policy, typegraph } from "@typegraph/sdk/index.ts"; import { KvRuntime } from "@typegraph/sdk/runtimes/kv.ts"; -export const tg = await typegraph("kv", (g: any) => { +export const tg = await typegraph("kv", (g) => { const kv = new KvRuntime("REDIS"); const pub = Policy.public(); g.expose({