Skip to content

Commit

Permalink
Use Specta v2-rc.1
Browse files Browse the repository at this point in the history
Co-authored-by: Brendan Allan <[email protected]>
  • Loading branch information
oscartbeaumont and Brendonovich committed Jul 17, 2023
1 parent ee02fc5 commit ebb9a98
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ workers = ["httpz", "httpz/workers", "httpz/ws"]
vercel = ["httpz", "httpz/vercel", "httpz/ws", "axum"]

[dependencies]
specta = { version = "1", default-features = false, features = ["serde"] }
specta = { version = "=2.0.0-rc.1", default-features = false, features = ["serde"] }
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false }
thiserror = { version = "1.0.43", default-features = false } # TODO: Possibly remove and do Specta typesafe errors manully?
Expand Down
28 changes: 19 additions & 9 deletions src/compiled_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ where
self.typ_store.clone()
}

#[cfg(not(feature = "unstable"))]
pub(crate) fn typ_store(&self) -> TypeDefs {
self.typ_store.clone()
}

#[cfg(feature = "unstable")]
pub fn queries(&self) -> &BTreeMap<String, ProcedureTodo<TCtx>> {
&self.queries.store
Expand Down Expand Up @@ -93,9 +98,12 @@ where
)
);

let queries_ts = generate_procedures_ts(&config, self.queries.store.iter());
let mutations_ts = generate_procedures_ts(&config, self.mutations.store.iter());
let subscriptions_ts = generate_procedures_ts(&config, self.subscriptions.store.iter());
let queries_ts =
generate_procedures_ts(&config, self.queries.store.iter(), &self.typ_store());
let mutations_ts =
generate_procedures_ts(&config, self.mutations.store.iter(), &self.typ_store());
let subscriptions_ts =
generate_procedures_ts(&config, self.subscriptions.store.iter(), &self.typ_store());

// TODO: Specta API + `ExportConfig` option for a formatter
writeln!(
Expand Down Expand Up @@ -146,16 +154,17 @@ export type Procedures = {{
}
}

for (_, typ) in types {
for (_, (sid, _)) in map {
writeln!(
file,
"\n{}",
ts::export_datatype(
&config,
&match typ {
Some(v) => v,
None => unreachable!(),
match types.get(sid) {
Some(Some(v)) => v,
_ => unreachable!(),
},
&types
)?
)?;
}
Expand All @@ -168,6 +177,7 @@ export type Procedures = {{
fn generate_procedures_ts<'a, Ctx: 'a>(
config: &ExportConfiguration,
procedures: impl ExactSizeIterator<Item = (&'a String, &'a ProcedureTodo<Ctx>)>,
type_store: &TypeDefs,
) -> String {
match procedures.len() {
0 => "never".to_string(),
Expand All @@ -181,10 +191,10 @@ fn generate_procedures_ts<'a, Ctx: 'a>(
"never".into()
}
#[allow(clippy::unwrap_used)] // TODO
ty => datatype(config, ty).unwrap(),
ty => datatype(config, ty, type_store).unwrap(),
};
#[allow(clippy::unwrap_used)] // TODO
let result_ts = datatype(config, &operation.ty.result).unwrap();
let result_ts = datatype(config, &operation.ty.result, type_store).unwrap();

// TODO: Specta API
format!(
Expand Down
1 change: 1 addition & 0 deletions src/internal/exec/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl<
E: std::fmt::Debug + std::error::Error,
> ConnectionTask<R, TCtx, S, E>
{
#[allow(dead_code)]
pub fn new(
ctx: TCtx,
executor: Executor<TCtx>,
Expand Down
7 changes: 5 additions & 2 deletions src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ mod tests {
exec::Response,
};

for (_, ty) in tys.into_iter().filter_map(|(sid, v)| v.map(|v| (sid, v))) {
for (_, ty) in tys
.iter()
.filter_map(|(sid, v)| v.as_ref().map(|v| (sid, v)))
{
file.write_all(b"\n\n").unwrap();
file.write_all(
export_datatype(&Default::default(), &ty)
export_datatype(&Default::default(), &ty, &tys)
.unwrap()
.as_bytes(),
)
Expand Down

0 comments on commit ebb9a98

Please sign in to comment.