File tree Expand file tree Collapse file tree 2 files changed +46
-8
lines changed
src/TreeToTS/functions/new Expand file tree Collapse file tree 2 files changed +46
-8
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,40 @@ describe('Test generated function buildQuery', () => {
266266 }
267267 }` ) ;
268268 } ) ;
269+ test ( 'Query with multiple aliases' , ( ) => {
270+ const matchExact = replSpace (
271+ builder ( 'query' , {
272+ __alias : {
273+ play : {
274+ cards : {
275+ name : true ,
276+ age : true ,
277+ bio : true ,
278+ } ,
279+ } ,
280+ shuffle : {
281+ cards : {
282+ name : true ,
283+ age : true ,
284+ bio : true ,
285+ } ,
286+ } ,
287+ } ,
288+ } ) ,
289+ ) ;
290+ matchExact ( `query{
291+ play:cards{
292+ name
293+ age
294+ bio
295+ }
296+ shuffle:cards{
297+ name
298+ age
299+ bio
300+ }
301+ }` ) ;
302+ } ) ;
269303 test ( 'Simple query with enums' , ( ) => {
270304 const enum Status {
271305 CREATED = 'CREATED' ,
Original file line number Diff line number Diff line change @@ -33,14 +33,18 @@ export const InternalsBuildQuery = (
3333 return `${ ibb ( args ? `${ k } (${ args } )` : k , o [ 1 ] , p , false ) } ` ;
3434 }
3535 if ( k === '__alias' ) {
36- const alias = Object . keys ( o ) [ 0 ] ;
37- const objectUnderAlias = o [ alias ] ;
38- if ( typeof objectUnderAlias !== 'object' || Array . isArray ( objectUnderAlias ) ) {
39- throw new Error ( 'Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}' ) ;
40- }
41- const operationName = Object . keys ( objectUnderAlias ) [ 0 ] ;
42- const operation = objectUnderAlias [ operationName ] ;
43- return ibb ( `${ alias } :${ operationName } ` , operation , p , false ) ;
36+ return Object . entries ( o )
37+ . map ( ( [ alias , objectUnderAlias ] ) => {
38+ if ( typeof objectUnderAlias !== 'object' || Array . isArray ( objectUnderAlias ) ) {
39+ throw new Error (
40+ 'Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}' ,
41+ ) ;
42+ }
43+ const operationName = Object . keys ( objectUnderAlias ) [ 0 ] ;
44+ const operation = objectUnderAlias [ operationName ] ;
45+ return ibb ( `${ alias } :${ operationName } ` , operation , p , false ) ;
46+ } )
47+ . join ( '\n' ) ;
4448 }
4549 const hasOperationName = root && options ?. operationName ? ' ' + options . operationName : '' ;
4650 const hasVariables = root && options ?. variables ?. $params ? `(${ options . variables ?. $params } )` : '' ;
You can’t perform that action at this time.
0 commit comments