Skip to content

Commit

Permalink
fix: address feedback and fix more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 13, 2024
1 parent f23bd47 commit a872a6e
Show file tree
Hide file tree
Showing 86 changed files with 4,334 additions and 24,329 deletions.
132 changes: 132 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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.7";
static MT_VERSION: &str = "0.5.0-rc.8";
if args.metatype_version != MT_VERSION {
return Err(InitError::VersionMismatch(MT_VERSION.into()));
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/src/typegraph/visitor2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct CurrentNode<'tg> {
pub type_node: &'tg TypeNode,
pub type_idx: u32,
pub path: SharedPath,
pub in_cycle: bool,
}

fn traverse_types_with_path<'tg, A, V, E>(
Expand All @@ -99,6 +100,7 @@ where
type_node,
type_idx,
path: path.clone(),
in_cycle: path.borrow().iter().any(|seg| seg.from == type_idx),
};
let cx = VisitorContext { tg, current_node };
match visit_fn(cx, &mut accumulator)? {
Expand Down
3 changes: 3 additions & 0 deletions src/metagen/src/shared/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub fn get_path_to_files(tg: &Typegraph, root: u32) -> Result<HashMap<u32, Vec<T
root,
Default::default(),
|cx, acc| -> Result<VisitNext, anyhow::Error> {
if cx.current_node.in_cycle {
return Ok(visitor2::VisitNext::Stop);
}
match cx.current_node.type_node {
TypeNode::File { .. } => {
let nearest_fn = cx.current_node.nearest_function();
Expand Down
1 change: 1 addition & 0 deletions src/metagen/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub async fn e2e_test(cases: Vec<E2eTestCase>) -> anyhow::Result<()> {
let test_cx = TestCtx {
typegraphs: typegraphs.clone(),
};
// SAFETY: this only runs in tests
unsafe {
std::env::set_var("METAGEN_CLIENT_RS_TEST", "1");
std::env::set_var("METAGEN_BIN_PATH", "main.rs");
Expand Down
3 changes: 1 addition & 2 deletions src/typegate/src/services/auth/protocols/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class InternalAuth extends Protocol {
const claims = {
provider: "internal",
};
// FIXME: this breaks substantial
return cryptoKeys.signJWT(claims, 60 * 10);
return cryptoKeys.signJWT(claims, 30);
}

private constructor(
Expand Down
57 changes: 11 additions & 46 deletions src/typegraph/core/src/global_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct SavedState {
#[derive(Default)]
pub struct Store {
// type ids can be pre-allocated
pub types: Vec<Option<Type>>,
pub types: Vec<Type>,
// the bool indicates weather the name was from
// user or generated placeholder (false)
pub type_by_names: IndexMap<Rc<str>, (NamedTypeRef, bool)>,
Expand Down Expand Up @@ -158,8 +158,9 @@ impl Store {
with_store(|s| s.type_by_names.get(name).map(|id| id.0.clone()))
}

pub fn assign_type_ref(id: TypeId, builder: TypeRefBuilder) -> Result<TypeRef> {
let type_ref = builder.with_id(id);
pub fn register_type_ref(builder: TypeRefBuilder) -> Result<TypeRef> {
let id = with_store_mut(|s| s.types.len()) as u32;
let type_ref = builder.with_id(id.into());
let res = type_ref.clone();

// very hacky solution where we keep track of
Expand Down Expand Up @@ -192,67 +193,32 @@ impl Store {
};
let res = type_ref.clone();
with_store_mut(move |s| -> Result<()> {
if s.types.len() < id.0 as usize {
return Err("assign_type_ref for unassigned id".into());
}
s.types[id.0 as usize] = Some(Type::Ref(type_ref));
s.types.push(Type::Ref(type_ref));
Ok(())
})?;
Self::register_type_name(name, name_ref, user_named)?;
Ok(res)
}
_ => {
with_store_mut(move |s| -> Result<()> {
if s.types.len() < id.0 as usize {
return Err("assign_type_ref for unassigned id".into());
}
s.types[id.0 as usize] = Some(Type::Ref(type_ref));
s.types.push(Type::Ref(type_ref));
Ok(())
})?;
Ok(res)
}
}
}

pub fn register_type_ref(builder: TypeRefBuilder) -> Result<TypeRef> {
let id = with_store_mut(|s| {
let id = s.types.len();
s.types.push(None);
id
}) as u32;
Self::assign_type_ref(id.into(), builder)
}
pub fn register_type_def(build: impl FnOnce(TypeId) -> Result<TypeDef>) -> Result<TypeId> {
// this works since the store is thread local
let id = with_store_mut(|s| s.types.len()) as u32;
let type_def = build(id.into())?;

pub fn preallocate_type_id() -> Result<TypeId> {
let id = with_store(|s| s.types.len()) as u32;
with_store_mut(move |s| -> Result<()> {
s.types.push(None);
s.types.push(type_def.into());
Ok(())
})?;
Ok(id.into())
}

pub fn replace_at_type_id(id: TypeId, def: impl Into<Type>) -> Result<TypeId> {
with_store_mut(move |s| -> Result<()> {
if s.types.len() < id.0 as usize {
return Err("replace_at_type_id replace for unassigned id".into());
}
s.types[id.0 as usize] = Some(def.into());
Ok(())
})?;
Ok(id)
}

pub fn register_type_def(build: impl FnOnce(TypeId) -> Result<TypeDef>) -> Result<TypeId> {
// this works since the store is thread local
let id = with_store_mut(|s| {
let id = s.types.len();
s.types.push(None);
id
}) as u32;
let type_def = build(id.into())?;

Self::replace_at_type_id(id.into(), type_def)

// // very hacky solution where we keep track of
// // explicitly named types in user_named_types
Expand Down Expand Up @@ -509,7 +475,6 @@ impl TypeId {
.get(self.0 as usize)
.cloned()
.ok_or_else(|| errors::object_not_found("type", self.0))
.and_then(|opt| opt.ok_or_else(|| "uninitialized type access".into()))
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/typegraph/core/src/params/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ mod test {
assert_eq!(
print_options.print(transform_data.query_input.into()),
indoc::indoc! {"
root: struct #6
root: struct #5
[a]: string #0
[first]: string #1
[second]: string #1
Expand Down
20 changes: 5 additions & 15 deletions src/typegraph/core/src/runtimes/prisma/relationship/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,23 @@ impl PrismaLink {
self
}

fn build_link(&self, type_id: Option<TypeId>) -> Result<TypeId> {
fn build_link(&self) -> Result<TypeId> {
let attr = RefAttr::runtime(
"prisma",
serde_json::to_value(PrismaRefData::from(self)).unwrap(),
);
let tref = match &self.target {
match &self.target {
PrismaLinkTarget::Direct(t) => TypeRef::from_type(t.clone(), attr),
PrismaLinkTarget::Indirect(n) => TypeRef::indirect(n, Some(attr)),
};
match type_id {
Some(id) => {
tref.register_under_id(id)?;
Ok(id)
}
None => tref.register().map(|t| t.id()),
}
.register()
.map(|t| t.id())
}
}

impl TypeBuilder for PrismaLink {
fn build(&self) -> Result<TypeId> {
self.build_link(None)
}

fn build_preallocated(&self, type_id: TypeId) -> Result<()> {
self.build_link(Some(type_id))?;
Ok(())
self.build_link()
}
}

Expand Down
Loading

0 comments on commit a872a6e

Please sign in to comment.