@@ -49,7 +49,7 @@ export interface URLComponents {
4949 path ?: string ;
5050 oDataQueryParams : KeyValuePairObjectStringNumber ;
5151 otherURLQueryParams : KeyValuePairObjectStringNumber ;
52- otherURLQueryStrings : string [ ] ;
52+ otherURLQueryOptions : any [ ] ;
5353}
5454
5555/**
@@ -119,7 +119,7 @@ export class GraphRequest {
119119 version : this . config . defaultVersion ,
120120 oDataQueryParams : { } ,
121121 otherURLQueryParams : { } ,
122- otherURLQueryStrings : [ ] ,
122+ otherURLQueryOptions : [ ] ,
123123 } ;
124124 this . _headers = { } ;
125125 this . _options = { } ;
@@ -240,8 +240,8 @@ export class GraphRequest {
240240 }
241241 }
242242
243- if ( urlComponents . otherURLQueryStrings . length !== 0 ) {
244- for ( const str of urlComponents . otherURLQueryStrings ) {
243+ if ( urlComponents . otherURLQueryOptions . length !== 0 ) {
244+ for ( const str of urlComponents . otherURLQueryOptions ) {
245245 query . push ( str ) ;
246246 }
247247 }
@@ -250,7 +250,9 @@ export class GraphRequest {
250250
251251 /**
252252 * @private
253- * @param queryDictionaryOrString
253+ * Parses the query parameters to set the urlComponents property of the GraphRequest object
254+ * @param {string|KeyValuePairObjectStringNumber } queryDictionaryOrString - The query parameter
255+ * @returns The same GraphRequest instance that is being called with
254256 */
255257 private parseQueryParameter ( queryDictionaryOrString : string | KeyValuePairObjectStringNumber ) : GraphRequest {
256258 if ( typeof queryDictionaryOrString === "string" ) {
@@ -266,20 +268,25 @@ export class GraphRequest {
266268 } else {
267269 this . parseQueryParamenterString ( queryDictionaryOrString ) ;
268270 }
269- } else {
271+ } else if ( queryDictionaryOrString . constructor === Object ) {
270272 for ( const key in queryDictionaryOrString ) {
271273 if ( queryDictionaryOrString . hasOwnProperty ( key ) ) {
272274 this . setURLComponentsQueryParamater ( key , queryDictionaryOrString [ key ] ) ;
273275 }
274276 }
277+ } else {
278+ /*Push values which are not of key-value structure.
279+ Example-> Handle an invalid input->.query(123) and let the Graph API respond with the error in the URL*/ this . urlComponents . otherURLQueryOptions . push ( queryDictionaryOrString ) ;
275280 }
276281
277282 return this ;
278283 }
279284
280285 /**
281286 * @private
282- * @param query
287+ * Parses the query parameter of string type to set the urlComponents property of the GraphRequest object
288+ * @param {string } queryParameter - the query parameters
289+ * returns nothing
283290 */
284291 private parseQueryParamenterString ( queryParameter : string ) : void {
285292 /* The query key-value pair must be split on the first equals sign to avoid errors in parsing nested query parameters.
@@ -290,13 +297,17 @@ export class GraphRequest {
290297 const paramValue = queryParameter . substring ( indexOfFirstEquals + 1 , queryParameter . length ) ;
291298 this . setURLComponentsQueryParamater ( paramKey , paramValue ) ;
292299 } else {
293- this . urlComponents . otherURLQueryStrings . push ( queryParameter ) ;
300+ /* Push values which are not of key-value structure.
301+ Example-> Handle an invalid input->.query(test), .query($select($select=name)) and let the Graph API respond with the error in the URL*/
302+ this . urlComponents . otherURLQueryOptions . push ( queryParameter ) ;
294303 }
295304 }
296305
297306 /**
298307 * @private
299- * @param query
308+ * Sets values into the urlComponents property of GraphRequest object.
309+ * @param {string } paramKey - the query parameter key
310+ * @param {string } paramValue - the query paramter value
300311 */
301312 private setURLComponentsQueryParamater ( paramKey : string , paramValue : string | number ) : void {
302313 if ( oDataQueryNames . indexOf ( paramKey ) !== - 1 ) {
@@ -307,19 +318,25 @@ export class GraphRequest {
307318 this . urlComponents . otherURLQueryParams [ paramKey ] = paramValue ;
308319 }
309320 }
310-
311- private isValidQueryKeyValuePair ( queryDictionaryOrString : string ) : boolean {
312- const indexofFirstEquals = queryDictionaryOrString . indexOf ( "=" ) ;
321+ /**
322+ * @private
323+ * Check if the query parameter string has a valid key-value structure
324+ * @param {string } queryString - the query parameter string. Example -> "name=value"
325+ * #returns true if the query string has a valid key-value structure else false
326+ */
327+ private isValidQueryKeyValuePair ( queryString : string ) : boolean {
328+ const indexofFirstEquals = queryString . indexOf ( "=" ) ;
313329 if ( indexofFirstEquals === - 1 ) {
314330 return false ;
315- } else {
316- const indexofOpeningParanthesis = queryDictionaryOrString . indexOf ( "(" ) ;
317- if ( indexofOpeningParanthesis !== - 1 && queryDictionaryOrString . indexOf ( "(" ) < indexofFirstEquals ) {
318- return false ;
319- }
331+ }
332+ const indexofOpeningParanthesis = queryString . indexOf ( "(" ) ;
333+ if ( indexofOpeningParanthesis !== - 1 && queryString . indexOf ( "(" ) < indexofFirstEquals ) {
334+ // Example -> .query($select($expand=true)) ;
335+ return false ;
320336 }
321337 return true ;
322338 }
339+
323340 /**
324341 * @private
325342 * Updates the custom headers and options for a request
0 commit comments