Skip to content

Commit

Permalink
fix: Remove prisma count (#916)
Browse files Browse the repository at this point in the history
<!--
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 -->

- Remove prisma count operation: it does not work, making it work like
on the prisma client would complicate the prisma runtime (until we have
output transformations...); Use aggregate instead.
- Increase the delay before exiting the process on the nodejs typegraph
client to give the CLI time to process all the output.
- Remove `quaint` logs on the typegate (too verbose).

<!-- 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
  • Loading branch information
Natoandro authored Nov 13, 2024
1 parent 865f2c9 commit 87efa1e
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 115 deletions.
172 changes: 86 additions & 86 deletions .ghjk/lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env("main")
.install(installs.deno)
.vars({
RUST_LOG:
"info,typegate=debug,deno=warn,swc_ecma_codegen=off,tracing::span=off",
"info,typegate=debug,deno=warn,swc_ecma_codegen=off,tracing::span=off,quaint=off",
TYPEGRAPH_VERSION: "0.0.3",
CLICOLOR_FORCE: "1",
CROSS_CONFIG: "tools/Cross.toml",
Expand Down
2 changes: 1 addition & 1 deletion src/metagen/src/client_ts/static/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function convertQueryNodeGql(
: `${node.instanceName}: ${node.nodeName}`;

const args = node.args;
if (args) {
if (args && Object.keys(args).length > 0) {
out = `${out} (${
Object.entries(args)
.map(([key, val]) => {
Expand Down
4 changes: 2 additions & 2 deletions src/typegate/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (!sharedConfig.rust_log) {
break;
case "DEBUG":
set(
"info,native=trace,sql_schema_connector=warn,tracing=warn,schema_core=warn",
"info,native=trace,sql_schema_connector=warn,tracing=warn,schema_core=warn,quaint=warn",
);
break;
case "WARNING":
Expand All @@ -27,7 +27,7 @@ if (!sharedConfig.rust_log) {
break;
case "INFO":
default:
set("info");
set("info,quaint=warn");
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/typegate/standalone/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ fn optional_module_path(path: &str) -> String {

pub fn init() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info,swc_ecma_codegen=off,tracing::span=off");
std::env::set_var(
"RUST_LOG",
"info,swc_ecma_codegen=off,tracing::span=off,quaint=off",
);
}
let mut builder = env_logger::Builder::from_default_env();
builder
Expand Down
4 changes: 0 additions & 4 deletions src/typegraph/core/src/runtimes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ impl crate::wit::runtimes::Guest for crate::Lib {
prisma_op!(runtime, model, Aggregate, "aggregate")
}

fn prisma_count(runtime: RuntimeId, model: CoreTypeId) -> Result<FuncParams, wit::Error> {
prisma_op!(runtime, model, Count, "count")
}

fn prisma_group_by(runtime: RuntimeId, model: CoreTypeId) -> Result<FuncParams, wit::Error> {
prisma_op!(runtime, model, GroupBy, "groupBy")
}
Expand Down
1 change: 0 additions & 1 deletion src/typegraph/core/wit/typegraph.wit
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ interface runtimes {
prisma-find-many: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-find-first: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-aggregate: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-count: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-group-by: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-create-one: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
prisma-create-many: func(runtime: runtime-id, model: type-id) -> result<func-params, error>;
Expand Down
9 changes: 0 additions & 9 deletions src/typegraph/deno/src/providers/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ export class PrismaRuntime extends Runtime {
return t.Func.fromTypeFunc(type);
}

/** create a function for a prisma `count` query */
count(model: string | Typedef): t.Func {
if (typeof model == "string") {
model = genRef(model);
}
const type = runtimes.prismaCount(this._id, model._id);
return t.Func.fromTypeFunc(type);
}

/** create a function for a prisma `groupBy` query */
groupBy(model: string | Typedef): t.Func {
if (typeof model == "string") {
Expand Down
4 changes: 2 additions & 2 deletions src/typegraph/deno/src/typegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export async function typegraph(
if (err.payload && !err.cause) {
err.cause = err.payload;
}
if ("stack" in err.cause) {
if (("cause" in err) && ("stack" in err.cause)) {
console.error(`Error in typegraph '${name}':`);
for (const msg of err.cause.stack) {
console.error(`- ${msg}`);
Expand Down Expand Up @@ -267,7 +267,7 @@ export async function typegraph(
log.debug("exiting");
process.exit(0);
}
}, 10);
}, 100);
}

--counter;
Expand Down
8 changes: 0 additions & 8 deletions src/typegraph/python/typegraph/providers/prisma.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ def aggregate(self, model: Union[str, t.typedef]) -> t.func:
raise ErrorStack(type.value)
return t.func.from_type_func(type.value)

def count(self, model: Union[str, t.typedef]) -> t.func:
if isinstance(model, str):
model = gen_ref(model)
type = runtimes.prisma_count(store, self.id, model._id)
if isinstance(type, Err):
raise ErrorStack(type.value)
return t.func.from_type_func(type.value)

def group_by(self, model: Union[str, t.typedef]) -> t.func:
if isinstance(model, str):
model = gen_ref(model)
Expand Down

0 comments on commit 87efa1e

Please sign in to comment.