Skip to content

Commit

Permalink
feat: check for set_interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Aug 28, 2024
1 parent fc8e3c8 commit 9e877b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/exceptions/not_implemented_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default class NotImplementedError extends Error {
statusCode: number;
constructor(message = 'Feature not implemented', ...params: string[]) {
super(...params);

Object.setPrototypeOf(this, NotImplementedError.prototype);

if (Error.captureStackTrace) {
Error.captureStackTrace(this, NotImplementedError);
}

this.name = 'NotImplementedError';
this.message = message;
this.statusCode = 501;
}
}
17 changes: 5 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { getTemplates, supportedLookups } from './inferred_mode/template_lookup'
export { default as QEdge } from './query_edge';
export { default as QNode } from './query_node';
export { default as InvalidQueryGraphError } from './exceptions/invalid_query_graph_error';
export { default as NotImplementedError } from './exceptions/not_implemented_error';
export * from './qedge2apiedge';

export default class TRAPIQueryHandler {
Expand Down Expand Up @@ -472,18 +473,10 @@ export default class TRAPIQueryHandler {
}

async _processQueryGraph(queryGraph: TrapiQueryGraph): Promise<QEdge[]> {
try {
const queryGraphHandler = new QueryGraph(queryGraph, this.options.schema);
const queryEdges = await queryGraphHandler.calculateEdges();
this.logs = [...this.logs, ...queryGraphHandler.logs];
return queryEdges;
} catch (err) {
if (err instanceof InvalidQueryGraphError || err instanceof SRINodeNormFailure) {
throw err;
} else {
throw new InvalidQueryGraphError();
}
}
const queryGraphHandler = new QueryGraph(queryGraph, this.options.schema);
const queryEdges = await queryGraphHandler.calculateEdges();
this.logs = [...this.logs, ...queryGraphHandler.logs];
return queryEdges;
}

async _edgesSupported(qEdges: QEdge[], metaKG: MetaKG): Promise<boolean> {
Expand Down
10 changes: 10 additions & 0 deletions src/query_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { resolveSRI } from 'biomedical_id_resolver';
import _ from 'lodash';
import * as utils from './utils';
import { TrapiQueryGraph } from '@biothings-explorer/types';
import NotImplementedError from './exceptions/not_implemented_error';

const debug = Debug('bte:biothings-explorer-trapi:query_graph');

Expand Down Expand Up @@ -182,6 +183,14 @@ export default class QueryGraph {
});
}

_validateQueryNoSetInterpretation(queryGraph: TrapiQueryGraph): boolean {
return Object.values(queryGraph.nodes).some((node) => {
if (node.set_interpretation) {
throw new NotImplementedError('NotImplementedError', 'Set interpretation is not yet implemented.')
}
})
}

_validate(queryGraph: TrapiQueryGraph): void {
this._validateEmptyEdges(queryGraph);
this._validateEmptyNodes(queryGraph);
Expand All @@ -193,6 +202,7 @@ export default class QueryGraph {
this._validateBatchSize(queryGraph);
this._validateCycles(queryGraph);
this._validateNoDuplicateQualifierTypes(queryGraph);
this._validateQueryNoSetInterpretation(queryGraph);
}

private async _findNodeCategories(curies: string[]): Promise<string[]> {
Expand Down

0 comments on commit 9e877b3

Please sign in to comment.