Skip to content

Commit

Permalink
feat: validate the deps too
Browse files Browse the repository at this point in the history
  • Loading branch information
j03-dev committed Dec 18, 2024
1 parent b10909c commit 8463fba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/typegate/engine/00_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const Meta = {
unregister: getOp("op_grpc_unregister"),
callGrpcMethod: getOp("op_call_grpc_method"),
},
py_validaton: {
py_validation: {
validate: getOp("op_validate"),
},
};
Expand Down
25 changes: 18 additions & 7 deletions src/typegate/src/runtimes/python/hooks/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,41 @@ export const codeValidations: PushHandler = async (
const { artifacts } = typegraph.meta;

for (const mat of typegraph.materializers) {
if (mat.name == "import_function") {
if (mat.name === "import_function") {
const pyModMat = typegraph.materializers[mat.data.mod as number];
const entryPoint = artifacts[pyModMat.data.entryPoint as string];
const moduleMeta = createArtifactMeta(title, entryPoint);
const depMetas = (pyModMat.data.deps as string[]).map((dep) =>
createArtifactMeta(title, artifacts[dep]),
createArtifactMeta(title, artifacts[dep])
);
const entryModulePath = await artifactStore.getLocalPath(
moduleMeta,
depMetas,
);

console.log({ entryModulePath });

try {
logger.info(
`Validating Python code at entry point: ${entryPoint.path}`,
);
Meta.py_validation.validate(entryModulePath);
logger.info(`${entryPoint.path} was validate`);

for (const dep of depMetas) {
const depsPath = await artifactStore.getLocalPath(dep);
logger.info(`Validating Python code for dependency: ${dep.path}`);
Meta.py_validation.validate(depsPath);
}

logger.info(
`Successfully validated Python code at entry point: ${entryPoint.path}`,
);
} catch (err) {
console.error(err);
console.error({ err });
throw new ValidationFailure(
`Python code validation error '${entryPoint.path}'`,
`Python code validation error at entry point '${entryPoint.path}': ${err.message}`,
);
}
}
}

return typegraph;
};
23 changes: 14 additions & 9 deletions src/typegate/src/typegate/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import { handleGraphQL } from "../services/graphql_service.ts";
import { getLogger } from "../log.ts";
import { MigrationFailure } from "../runtimes/prisma/hooks/run_migrations.ts";
import { DenoFailure } from "../runtimes/deno/hooks/mod.ts";
import introspectionJson from "../typegraphs/introspection.json" with { type: "json" };
import { ValidationFailure } from "../runtimes/python/hooks/mod.ts";
import introspectionJson from "../typegraphs/introspection.json" with {
type: "json",
};
import { ArtifactService } from "../services/artifact_service.ts";
import type { ArtifactStore } from "./artifacts/mod.ts";
// TODO move from tests (MET-497)
Expand Down Expand Up @@ -204,6 +207,8 @@ export class Typegate implements AsyncDisposable {
response.setFailure(e.errors[0]);
} else if (e instanceof DenoFailure) {
response.setFailure(e.failure);
} else if (e instanceof ValidationFailure) {
response.setFailure(e.failure);
} else {
response.setFailure({
reason: "Unknown",
Expand Down Expand Up @@ -404,14 +409,14 @@ export class Typegate implements AsyncDisposable {

const introspection = enableIntrospection
? await TypeGraph.init(
this,
introspectionDef,
new SecretManager(introspectionDef, {}),
{
typegraph: TypeGraphRuntime.init(tgDS, [], {}),
},
null,
)
this,
introspectionDef,
new SecretManager(introspectionDef, {}),
{
typegraph: TypeGraphRuntime.init(tgDS, [], {}),
},
null,
)
: null;

const tg = await TypeGraph.init(
Expand Down

0 comments on commit 8463fba

Please sign in to comment.