From 9f8acc6a779dea590bca07688537333353296eba Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 3 Nov 2022 13:36:52 -0400 Subject: [PATCH 1/5] feat: pass in qualifier-constraints for TRAPI queries --- src/builder/trapi_query_builder.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/builder/trapi_query_builder.js b/src/builder/trapi_query_builder.js index f4daee0..4fd00fe 100644 --- a/src/builder/trapi_query_builder.js +++ b/src/builder/trapi_query_builder.js @@ -74,6 +74,10 @@ module.exports = class TRAPIQueryBuilder { }, "submitter": "infores:bte" }; + const qualfierConstraints = APIEdge.reasoner_edge.getQualifierConstraints(); + if (qualfierConstraints) { + qg.message.query_graph.edges.e01.qualifier_constraints = qualfierConstraints; + } const xmaturityMap = { ci: "staging", test: "test", From ccca05f0e48b528a85f9be98222008c26d537a05 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 3 Nov 2022 13:37:34 -0400 Subject: [PATCH 2/5] style: formatting --- src/builder/trapi_query_builder.js | 208 ++++++++++++++--------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/src/builder/trapi_query_builder.js b/src/builder/trapi_query_builder.js index 4fd00fe..8cbbe97 100644 --- a/src/builder/trapi_query_builder.js +++ b/src/builder/trapi_query_builder.js @@ -6,120 +6,120 @@ const nunjucksConfig = require("./nunjucks_config"); const env = nunjucks.configure({ autoescape: false }); nunjucksConfig(env); module.exports = class TRAPIQueryBuilder { - /** - * Constructor for Query Builder - * @param {object} APIEdge - BTE Edge object with input field provided - */ - constructor(APIEdge) { - this.start = 0 - this.hasNext = false - this.APIEdge = APIEdge; - this.originalSubmitter; - } + /** + * Constructor for Query Builder + * @param {object} APIEdge - BTE Edge object with input field provided + */ + constructor(APIEdge) { + this.start = 0; + this.hasNext = false; + this.APIEdge = APIEdge; + this.originalSubmitter; + } - getUrl() { - return this.APIEdge.query_operation.server + this.APIEdge.query_operation.path; - } + getUrl() { + return this.APIEdge.query_operation.server + this.APIEdge.query_operation.path; + } - _getUrl(APIEdge, input) { - let server = APIEdge.query_operation.server; - if (server.endsWith('/')) { - server = server.substring(0, server.length - 1) - }; - let path = APIEdge.query_operation.path; - if (Array.isArray(APIEdge.query_operation.path_params)) { - APIEdge.query_operation.path_params.map(param => { - const val = APIEdge.query_operation.params[param]; - path = path.replace("{" + param + "}", val).replace("{inputs[0]}", input); - }); - } - return server + path; + _getUrl(APIEdge, input) { + let server = APIEdge.query_operation.server; + if (server.endsWith("/")) { + server = server.substring(0, server.length - 1); } - - /** - * Construct input based on method and inputSeparator - */ - _getInput(APIEdge) { - return APIEdge.input; + let path = APIEdge.query_operation.path; + if (Array.isArray(APIEdge.query_operation.path_params)) { + APIEdge.query_operation.path_params.map(param => { + const val = APIEdge.query_operation.params[param]; + path = path.replace("{" + param + "}", val).replace("{inputs[0]}", input); + }); } + return server + path; + } - addSubmitter(submitter) { - this.originalSubmitter = submitter; - } + /** + * Construct input based on method and inputSeparator + */ + _getInput(APIEdge) { + return APIEdge.input; + } - /** - * Construct TRAPI request body - */ - _getRequestBody(APIEdge, input) { - const qg = { - "message": { - "query_graph": { - "nodes": { - "n0": { - "ids": Array.isArray(input) ? input : [input], - "categories": ["biolink:" + APIEdge.association.input_type] - }, - "n1": { - "categories": ["biolink:" + APIEdge.association.output_type] - } - }, - "edges": { - "e01": { - "subject": "n0", - "object": "n1", - "predicates": ["biolink:" + APIEdge.association.predicate] - } - } - } - }, - "submitter": "infores:bte" - }; - const qualfierConstraints = APIEdge.reasoner_edge.getQualifierConstraints(); - if (qualfierConstraints) { - qg.message.query_graph.edges.e01.qualifier_constraints = qualfierConstraints; - } - const xmaturityMap = { - ci: "staging", - test: "test", - prod: "prod", - dev: "dev", - } - if (process.env.INSTANCE_ENV) qg.submitter += `; bte-${xmaturityMap[process.env.INSTANCE_ENV]}`; - if (this.originalSubmitter) qg.submitter += `; subquery for client "${this.originalSubmitter}"`; - return qg; - } + addSubmitter(submitter) { + this.originalSubmitter = submitter; + } - /** - * Construct the request config for Axios reqeust. - */ - constructAxiosRequestConfig() { - const input = this._getInput(this.APIEdge); - const config = { - url: this._getUrl(this.APIEdge, input), - data: this._getRequestBody(this.APIEdge, input), - method: this.APIEdge.query_operation.method, - headers: { - 'Content-Type': 'application/json' + /** + * Construct TRAPI request body + */ + _getRequestBody(APIEdge, input) { + const qg = { + message: { + query_graph: { + nodes: { + n0: { + ids: Array.isArray(input) ? input : [input], + categories: ["biolink:" + APIEdge.association.input_type], }, - } - this.config = config; - return config; + n1: { + categories: ["biolink:" + APIEdge.association.output_type], + }, + }, + edges: { + e01: { + subject: "n0", + object: "n1", + predicates: ["biolink:" + APIEdge.association.predicate], + }, + }, + }, + }, + submitter: "infores:bte", + }; + const qualfierConstraints = APIEdge.reasoner_edge.getQualifierConstraints(); + if (qualfierConstraints) { + qg.message.query_graph.edges.e01.qualifier_constraints = qualfierConstraints; } + const xmaturityMap = { + ci: "staging", + test: "test", + prod: "prod", + dev: "dev", + }; + if (process.env.INSTANCE_ENV) qg.submitter += `; bte-${xmaturityMap[process.env.INSTANCE_ENV]}`; + if (this.originalSubmitter) qg.submitter += `; subquery for client "${this.originalSubmitter}"`; + return qg; + } - needPagination(apiResponse) { - this.hasNext = false; - return false - } + /** + * Construct the request config for Axios reqeust. + */ + constructAxiosRequestConfig() { + const input = this._getInput(this.APIEdge); + const config = { + url: this._getUrl(this.APIEdge, input), + data: this._getRequestBody(this.APIEdge, input), + method: this.APIEdge.query_operation.method, + headers: { + "Content-Type": "application/json", + }, + }; + this.config = config; + return config; + } - getNext() { - const config = this.constructAxiosRequestConfig(this.APIEdge); - return config; - } + needPagination(apiResponse) { + this.hasNext = false; + return false; + } + + getNext() { + const config = this.constructAxiosRequestConfig(this.APIEdge); + return config; + } - getConfig() { - if (this.hasNext === false) { - return this.constructAxiosRequestConfig(this.APIEdge); - } - return this.getNext(); + getConfig() { + if (this.hasNext === false) { + return this.constructAxiosRequestConfig(this.APIEdge); } -} + return this.getNext(); + } +}; From eda28e70c1f1e4ba27d5029bdd0340de267e9cab Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 3 Nov 2022 13:39:33 -0400 Subject: [PATCH 3/5] fix: optional chaining for ease of testing --- src/builder/trapi_query_builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builder/trapi_query_builder.js b/src/builder/trapi_query_builder.js index 8cbbe97..3f0729a 100644 --- a/src/builder/trapi_query_builder.js +++ b/src/builder/trapi_query_builder.js @@ -74,7 +74,7 @@ module.exports = class TRAPIQueryBuilder { }, submitter: "infores:bte", }; - const qualfierConstraints = APIEdge.reasoner_edge.getQualifierConstraints(); + const qualfierConstraints = APIEdge.reasoner_edge?.getQualifierConstraints?.(); if (qualfierConstraints) { qg.message.query_graph.edges.e01.qualifier_constraints = qualfierConstraints; } From 2b7f8d9442afbdd70f8108ff9179ad1e27878f14 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Tue, 15 Nov 2022 13:13:47 -0500 Subject: [PATCH 4/5] fix: typo --- src/builder/trapi_query_builder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builder/trapi_query_builder.js b/src/builder/trapi_query_builder.js index 3f0729a..b235184 100644 --- a/src/builder/trapi_query_builder.js +++ b/src/builder/trapi_query_builder.js @@ -74,9 +74,9 @@ module.exports = class TRAPIQueryBuilder { }, submitter: "infores:bte", }; - const qualfierConstraints = APIEdge.reasoner_edge?.getQualifierConstraints?.(); - if (qualfierConstraints) { - qg.message.query_graph.edges.e01.qualifier_constraints = qualfierConstraints; + const qualifierConstraints = APIEdge.reasoner_edge?.getQualifierConstraints?.(); + if (qualifierConstraints) { + qg.message.query_graph.edges.e01.qualifier_constraints = qualifierConstraints; } const xmaturityMap = { ci: "staging", From bfb2ab4f5d5eaaeb46d1667b3e60ba2f80f4df94 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 8 Dec 2022 14:38:14 -0500 Subject: [PATCH 5/5] test: fix tests --- __test__/integration/integration.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__test__/integration/integration.test.js b/__test__/integration/integration.test.js index 314e735..a29e2b5 100644 --- a/__test__/integration/integration.test.js +++ b/__test__/integration/integration.test.js @@ -60,8 +60,8 @@ describe("Integration test", () => { test("check response", async () => { const query = new q(edges); const res = await query.query(false); - const mydisease_res = await axios.get("http://mydisease.info/v1/disease/MONDO:0002494?fields=mondo.descendants&dotfield=true"); - expect(res.length).toEqual(mydisease_res.data["mondo.descendants"].length) + const mydisease_res = await axios.get("http://mydisease.info/v1/disease/MONDO:0002494?fields=mondo.children&dotfield=true"); + expect(res.length).toEqual(mydisease_res.data["mondo.children"].length) }) }) })