Skip to content

Commit

Permalink
Use the TRAPI spec to determine properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Oct 6, 2022
1 parent 207c81e commit 3edd604
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ exports.getTemplates = getTemplates;
exports.supportedLookups = supportedLookups;

exports.TRAPIQueryHandler = class TRAPIQueryHandler {
constructor(options = {}, smartAPIPath = undefined, predicatesPath = undefined, includeReasoner = true) {
constructor(schema, options = {}, smartAPIPath = undefined, predicatesPath = undefined, includeReasoner = true) {
this.schema = schema;
this.logs = [];
this.options = options;
this.includeReasoner = includeReasoner;
Expand Down Expand Up @@ -92,14 +93,15 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
*/
async _processQueryGraph(queryGraph) {
try {
let queryGraphHandler = new QueryGraph(queryGraph);
let queryGraphHandler = new QueryGraph(queryGraph, this.schema);
let queryExecutionEdges = await queryGraphHandler.calculateEdges();
this.logs = [...this.logs, ...queryGraphHandler.logs];
return queryExecutionEdges;
} catch (err) {
if (err instanceof InvalidQueryGraphError || err instanceof id_resolver.SRIResolverFailiure) {
throw err;
} else {
console.log(err.stack);
throw new InvalidQueryGraphError();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/query_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const _ = require('lodash');
const utils = require('./utils');

module.exports = class QueryGraphHandler {
constructor(queryGraph) {
constructor(queryGraph, schema) {
this.queryGraph = queryGraph;
this.schema = schema;
this.logs = [];
}

Expand Down Expand Up @@ -84,7 +85,7 @@ module.exports = class QueryGraphHandler {
}

_validateNodeProperties(queryGraph) {
const nodeProperties = new Set(["ids", "categories", "is_set", "constraints"]);
const nodeProperties = new Set(Object.keys(this.schema.components.schemas.QNode.properties));
const badProperties = new Set();
for (const nodeID in queryGraph.nodes) {
for (const property in queryGraph.nodes[nodeID]) {
Expand All @@ -106,7 +107,7 @@ module.exports = class QueryGraphHandler {
}

_validateEdgeProperties(queryGraph) {
const edgeProperties = new Set(["predicates", "subject", "object", "knowledge_type", "attribute_constraints", "qualifier_constraints"]);
const edgeProperties = new Set(Object.keys(this.schema.components.schemas.QEdge.properties));
const badProperties = new Set();
for (const edgeID in queryGraph.edges) {
for (const property in queryGraph.edges[edgeID]) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": false,
"noImplicitAny": false
"noImplicitAny": false,
"skipLibCheck": true
},
"include": [
"./src/**/*",
Expand Down

0 comments on commit 3edd604

Please sign in to comment.