From f9e34e547e9fdab3c277e1c6fc50e50c97142463 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Thu, 19 Dec 2024 19:13:01 +0100 Subject: [PATCH] Add node api version to query options --- managers/graph-operations-manager.js | 4 +++- services/input-service.js | 4 ++++ services/node-api-service/implementations/http-service.js | 8 ++++---- services/validation-service.js | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/managers/graph-operations-manager.js b/managers/graph-operations-manager.js index 91d0dbe..35b24cc 100644 --- a/managers/graph-operations-manager.js +++ b/managers/graph-operations-manager.js @@ -37,7 +37,7 @@ export default class GraphOperationsManager { * @returns {Promise} A Promise that resolves to the query result. */ async query(queryString, queryType, options = {}) { - const { endpoint, port, maxNumberOfRetries, frequency, authToken, paranetUAL, repository } = + const { endpoint, port, maxNumberOfRetries, frequency, authToken, paranetUAL, repository, nodeApiVersion } = this.inputService.getQueryArguments(options); this.validationService.validateGraphQuery( @@ -49,6 +49,7 @@ export default class GraphOperationsManager { frequency, authToken, repository, + nodeApiVersion, ); const operationId = await this.nodeApiService.query( @@ -59,6 +60,7 @@ export default class GraphOperationsManager { queryType, paranetUAL, repository, + nodeApiVersion, ); return this.nodeApiService.getOperationResult( diff --git a/services/input-service.js b/services/input-service.js index 621786c..0600de2 100644 --- a/services/input-service.js +++ b/services/input-service.js @@ -98,6 +98,7 @@ export default class InputService { authToken: this.getAuthToken(options), paranetUAL: this.getParanetUAL(options), repository: this.getRepository(options), + nodeApiVersion: this.getNodeApiVersion(options), }; } @@ -416,4 +417,7 @@ export default class InputService { getAssertionCachedLocally(options) { return options.assertionCachedLocally ?? false; } + getNodeApiVersion(options) { + return options.ndeApiVersion ?? config.nodeApiVersion ?? '/v1' + } } diff --git a/services/node-api-service/implementations/http-service.js b/services/node-api-service/implementations/http-service.js index 0c7dde4..c859933 100644 --- a/services/node-api-service/implementations/http-service.js +++ b/services/node-api-service/implementations/http-service.js @@ -179,11 +179,11 @@ export default class HttpService { } } - async query(endpoint, port, authToken, query, type, paranetUAL, repository) { + async query(endpoint, port, authToken, query, type, paranetUAL, repository, nodeApiVersion) { try { const response = await axios({ method: 'post', - url: `${this.getBaseUrl(endpoint, port)}/query`, + url: `${this.getBaseUrl(endpoint, port, nodeApiVersion)}/query`, data: { query, type, repository, paranetUAL }, headers: this.prepareRequestConfig(authToken), }); @@ -316,7 +316,7 @@ export default class HttpService { return {}; } - getBaseUrl(endpoint, port) { - return `${endpoint}:${port}${this.apiVersion}`; + getBaseUrl(endpoint, port, apiVersion = null) { + return `${endpoint}:${port}${apiVersion ?? this.apiVersion}`; } } diff --git a/services/validation-service.js b/services/validation-service.js index a8b79a9..6ec5567 100644 --- a/services/validation-service.js +++ b/services/validation-service.js @@ -29,6 +29,7 @@ export default class ValidationService { frequency, authToken, repository, + nodeApiVersion, ) { this.validateQueryString(queryString); this.validateQueryType(queryType); @@ -37,6 +38,7 @@ export default class ValidationService { this.validateMaxNumberOfRetries(maxNumberOfRetries); this.validateFrequency(frequency); this.validateAuthToken(authToken); + this.validateNodeApiVersion(nodeApiVersion); if (repository) { this.validateRepository(repository); @@ -773,4 +775,8 @@ export default class ValidationService { minimumNumberOfFinalizationConfirmations, ); } + + validateNodeApiVersion(nodeApiVersion) { + nodeApiVersion === '/v1' || nodeApiVersion === '/v0' + } }