Skip to content

Commit

Permalink
Merge pull request #56 from biothings/revert-55-revert-38-fix-851-bte
Browse files Browse the repository at this point in the history
Revert "Revert "Read MetaKG from global var if exists - `v1/meta_knowledge_graph_v1`""
  • Loading branch information
tokebe authored Nov 13, 2024
2 parents d229d85 + e48406e commit ade5f18
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/predicates.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/smartapi_specs.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ export const tasks: TaskByRoute = {
asyncquery_v1: (taskInfo: TaskInfo) => V1AsyncQuery.task(taskInfo),
asyncquery_v1_by_api: (taskInfo: TaskInfo) => V1AsyncQueryByAPI.task(taskInfo),
asyncquery_v1_by_team: (taskInfo: TaskInfo) => V1AsyncQueryByTeam.task(taskInfo),
// load MetaKG from global
meta_knowledge_graph_v1: (taskInfo: TaskInfo) => V1MetaKG.task(taskInfo),
// Not threaded due to being lightweight/speed being higher priority
// performance: (taskInfo: TaskInfo) => Performance.task(taskInfo),
// metakg: (taskInfo: TaskInfo) => MetaKG.task(taskInfo),
// meta_knowledge_graph_v1: (taskInfo: TaskInfo) => V1MetaKG.task(taskInfo),
// meta_knowledge_graph_v1_by_api: (taskInfo: TaskInfo) => V1MetaKGByAPI.task(taskInfo),
// meta_knowledge_graph_v1_by_team: (taskInfo: TaskInfo) => V1MetaKGByTeam.task(taskInfo),
};
26 changes: 23 additions & 3 deletions src/routes/v1/meta_knowledge_graph_v1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import path from "path";
import { TaskInfo } from "@biothings-explorer/types";
import handler from "../../controllers/meta_knowledge_graph";
import * as utils from "../../utils/common";
import { runTask, taskResponse, taskError } from "../../controllers/threading/threadHandler";
import { Express, NextFunction, Request, Response, RequestHandler } from "express";

class MetaKG {
Expand All @@ -8,16 +11,33 @@ class MetaKG {
.route("/v1/meta_knowledge_graph")
.get((async (_req: Request, res: Response, next: NextFunction) => {
try {
const metaKGHandler = new handler(undefined);
const kg = await metaKGHandler.getKG();
const response = await runTask(_req, res, path.parse(__filename).name);
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(kg));
res.end(JSON.stringify(response));
} catch (error) {
next(error);
}
}) as RequestHandler)
.all(utils.methodNotAllowed);
}

async task(taskInfo: TaskInfo) {
try {
let kg = undefined;

// read metakg from files if not globally defined
if(!taskInfo.data.options.metakg) {
const metaKGHandler = new handler(undefined);
kg = await metaKGHandler.getKG();
} else {
kg = taskInfo.data.options.metakg;
}
// response.logs = utils.filterForLogLevel(response.logs, options.logLevel);
return taskResponse(kg);
} catch (error) {
taskError(error as Error);
}
}
}

export default new MetaKG();

0 comments on commit ade5f18

Please sign in to comment.