@@ -102,11 +102,13 @@ export function renderSelectionSet(
102102
103103 for ( const item of selectionSet ) {
104104 if ( item . kind === 'InlineFragment' ) {
105- lines . push ( `${ indent ( depth ) } ... on ${ item . typeCondition } ` ) ;
105+ lines . push ( `${ indent ( depth ) } ... on ${ item . typeCondition } { ` ) ;
106106
107107 for ( const property of item . selections ?? [ ] ) {
108108 lines . push ( `${ indent ( depth + 1 ) } ${ property . name } ` ) ;
109109 }
110+
111+ lines . push ( `${ indent ( depth ) } }` ) ;
110112 }
111113 }
112114
@@ -169,7 +171,19 @@ export function renderFetchNode(node: FetchNodePlan, depth = 0): string {
169171 lines . push ( `${ indent ( depth + 1 ) } } =>` ) ;
170172 }
171173
172- lines . push ( renderMultilineBlock ( print ( parse ( node . operation ) ) , depth + 2 ) , `${ indent ( depth ) } }` ) ;
174+ const slice = node . operation . includes ( '_entities' ) ? 2 : 1 ;
175+
176+ lines . push (
177+ `${ indent ( depth + 1 ) } {` ,
178+ renderMultilineBlock (
179+ print ( parse ( node . operation ) )
180+ . split ( '\n' )
181+ . slice ( slice , slice * - 1 )
182+ . join ( '\n' ) ,
183+ depth + 1 ,
184+ ) ,
185+ `${ indent ( depth + 1 ) } }` ,
186+ ) ;
173187
174188 return lines . join ( '\n' ) ;
175189}
@@ -178,31 +192,37 @@ export function renderBatchFetchNode(node: BatchFetchNodePlan, depth = 0): strin
178192 const lines : string [ ] = [ ] ;
179193 lines . push ( `${ indent ( depth ) } BatchFetch(service: "${ node . serviceName } ") {` ) ;
180194
181- for ( const alias of node . entityBatch . aliases ) {
195+ for ( let i = 0 ; i < node . entityBatch . aliases . length ; i ++ ) {
196+ const alias = node . entityBatch . aliases [ i ] ;
197+
182198 lines . push (
183199 `${ indent ( depth + 1 ) } ${ alias . alias } {` ,
184- `${ indent ( depth + 2 ) } paths [` ,
185- ...alias . paths . map (
186- ( path , index ) =>
187- `${ indent ( depth + 3 ) } ${ renderFlattenPath ( path ) } ${ index < alias . paths . length - 1 ? ',' : '' } ` ,
188- ) ,
200+ `${ indent ( depth + 2 ) } paths: [` ,
201+ ...alias . paths . map ( path => `${ indent ( depth + 3 ) } "${ renderFlattenPath ( path ) } "` ) ,
189202 `${ indent ( depth + 2 ) } ]` ,
190- `${ indent ( depth + 2 ) } {` ,
191203 ) ;
204+
192205 const requires = renderSelectionSet ( alias . requires , depth + 3 ) ;
193- if ( requires ) lines . push ( requires ) ;
194- lines . push (
195- `${ indent ( depth + 2 ) } }` ,
196- `${ indent ( depth + 1 ) } }` ,
197- `${ indent ( depth + 1 ) } {` ,
198- renderMultilineBlock (
199- print ( parse ( node . operation ) ) . split ( '\n' ) . slice ( 1 , - 1 ) . join ( '\n' ) ,
200- depth + 1 ,
201- ) ,
202- `${ indent ( depth + 1 ) } }` ,
203- ) ;
206+
207+ if ( requires ) {
208+ lines . push ( `${ indent ( depth + 2 ) } {` , requires , `${ indent ( depth + 2 ) } }` ) ;
209+ }
210+
211+ if ( i < node . entityBatch . aliases . length - 1 ) {
212+ lines . push ( `${ indent ( depth + 1 ) } }` ) ;
213+ }
204214 }
205- lines . push ( `${ indent ( depth ) } }` ) ;
215+
216+ lines . push (
217+ `${ indent ( depth + 1 ) } }` ,
218+ `${ indent ( depth + 1 ) } {` ,
219+ renderMultilineBlock (
220+ print ( parse ( node . operation ) ) . split ( '\n' ) . slice ( 1 , - 1 ) . join ( '\n' ) ,
221+ depth + 1 ,
222+ ) ,
223+ `${ indent ( depth + 1 ) } }` ,
224+ `${ indent ( depth ) } }` ,
225+ ) ;
206226
207227 return lines . join ( '\n' ) ;
208228}
@@ -597,7 +617,7 @@ function visitNode(
597617 ) ;
598618 break ;
599619
600- case 'Sequence' :
620+ case 'Sequence' : {
601621 result = null ;
602622
603623 let prevChild : QueryPlanNode | null = null ;
@@ -619,6 +639,7 @@ function visitNode(
619639 }
620640
621641 break ;
642+ }
622643
623644 case 'Parallel' :
624645 result . children = [ ] ;
0 commit comments