@@ -74,13 +74,6 @@ class WOQLClient {
7474 }
7575}
7676
77- /* function WOQLClient(serverUrl, params) {
78- // current connection context variables
79- this.connectionConfig = new ConnectionConfig(serverUrl, params);
80- this.databaseList = [];
81- this.organizationList = [];
82- } */
83-
8477/**
8578 * set the api key to access the cloud resources
8679 * @param {string } accessToken
@@ -1138,26 +1131,36 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
11381131
11391132/**
11401133 *
1141- * @param {typedef.DocParamsGet } [params] - the get parameters
1134+ * @param {typedef.DocParamsGet } [params] - the get parameters,
1135+ * you can pass document query search template with the params
11421136 * @param {string } [dbId] - the database id
11431137 * @param {string } [branch] - the database branch
11441138 * @param {string } [lastDataVersion] the last data version tracking id.
11451139 * @param {boolean } [getDataVersion] If true the function will return object having result
11461140 * and dataVersion.
1147- * @param {object } [query] If a query object is provided, the function will use it to
1148- * query the database.
1141+ * @param {object } [query] document query search template
11491142 * @returns {Promise } A promise that returns the call response object or object having *result*
11501143 * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
11511144 * @example
11521145 * //return the schema graph as a json array
1153- * client.getDocument({"graph_type":"schema","as_list":true})
1146+ * client.getDocument({"graph_type":"schema","as_list":true}).then(result={
1147+ * console.log(result)
1148+ * })
11541149 *
11551150 * //retutn the Country class document from the schema graph
1156- * client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"})
1151+ * client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"}).then(result={
1152+ * console.log(result)
1153+ * })
11571154 *
1155+ * //pass a document query template to query the document interface
1156+ * const queryTemplate = { "name": "Ireland", "@type":"Country" }
1157+ * client.getDocument({"graph_type":"schema","as_list":true,
1158+ * query:queryTemplate}).then(result=>{
1159+ * console.log(result)
1160+ * })
11581161 *
1159- * // Here we will pass true to show how to get dataVersion
11601162 *
1163+ * // Here we will pass true to show how to get dataVersion
11611164 * const response = await client.getDocument({"graph_type":"schema","as_list":true},
11621165 * "",
11631166 * "",
@@ -1192,12 +1195,19 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11921195 if ( typeof lastDataVersion === 'string' && lastDataVersion !== '' ) {
11931196 this . customHeaders ( { 'TerminusDB-Data-Version' : lastDataVersion } ) ;
11941197 }
1195-
1198+ let queryDoc ;
11961199 if ( query ) {
1200+ queryDoc = query ;
1201+ } else if ( params && typeof params === 'object' && params . query ) {
1202+ queryDoc = params . query ;
1203+ delete params . query ;
1204+ }
1205+ // if query we are send a get with a payload
1206+ if ( queryDoc ) {
11971207 return this . dispatch (
11981208 CONST . QUERY_DOCUMENT ,
11991209 this . connectionConfig . documentURL ( params ) ,
1200- query ,
1210+ queryDoc ,
12011211 getDataVersion ,
12021212 ) ;
12031213 }
0 commit comments