* Executes the graph traversal. * @param {String|Object} query * @param {Object} parameters * @param {GraphQueryOptions} options
(query, parameters, options)
| 86 | * @param {GraphQueryOptions} options |
| 87 | */ |
| 88 | async send(query, parameters, options) { |
| 89 | if (Array.isArray(parameters)) { |
| 90 | throw new TypeError('Parameters must be a Object instance as an associative array'); |
| 91 | } |
| 92 | |
| 93 | if (!query) { |
| 94 | throw new TypeError('Query must be defined'); |
| 95 | } |
| 96 | |
| 97 | const execOptions = new GraphExecutionOptions( |
| 98 | options, this._client, this._graphBaseOptions, this._defaultProfileRetryPolicy); |
| 99 | |
| 100 | if (execOptions.getGraphSource() === 'a') { |
| 101 | const host = await this._getAnalyticsMaster(); |
| 102 | execOptions.setPreferredHost(host); |
| 103 | } |
| 104 | |
| 105 | // A query object that allows to plugin any executable thing |
| 106 | const isQueryObject = typeof query === 'object' && query.graphLanguage && query.value && query.queryWriterFactory; |
| 107 | |
| 108 | if (isQueryObject) { |
| 109 | // Use the provided graph language to override the current |
| 110 | execOptions.setGraphLanguage(query.graphLanguage); |
| 111 | } |
| 112 | |
| 113 | this._setGraphProtocol(execOptions); |
| 114 | execOptions.setGraphPayload(); |
| 115 | parameters = GraphExecutor._buildGraphParameters(parameters, execOptions.getGraphSubProtocol()); |
| 116 | |
| 117 | if (typeof query !== 'string') { |
| 118 | // Its a traversal that needs to be converted |
| 119 | // Transforming the provided query into a traversal requires the protocol to be set first. |
| 120 | // Query writer factory can be defined in the options or in the query object |
| 121 | let queryWriter = execOptions.getQueryWriter(); |
| 122 | |
| 123 | if (isQueryObject) { |
| 124 | queryWriter = query.queryWriterFactory(execOptions.getGraphSubProtocol()); |
| 125 | } else if (!queryWriter) { |
| 126 | queryWriter = GraphExecutor._writerFactory(execOptions.getGraphSubProtocol()); |
| 127 | } |
| 128 | |
| 129 | query = queryWriter(!isQueryObject ? query : query.value); |
| 130 | } |
| 131 | |
| 132 | return await this._executeGraphQuery(query, parameters, execOptions); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Sends the graph traversal. |
no test coverage detected