@@ -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,23 @@ 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+ try {
177+ lines . push (
178+ `${ indent ( depth + 1 ) } {` ,
179+ renderMultilineBlock (
180+ print ( parse ( node . operation ) )
181+ . split ( '\n' )
182+ . slice ( slice , slice * - 1 )
183+ . join ( '\n' ) ,
184+ depth + 1 ,
185+ ) ,
186+ `${ indent ( depth + 1 ) } }` ,
187+ ) ;
188+ } catch {
189+ lines . push ( `${ indent ( depth + 1 ) } ${ node . operation } ` ) ;
190+ }
173191
174192 return lines . join ( '\n' ) ;
175193}
@@ -178,31 +196,41 @@ export function renderBatchFetchNode(node: BatchFetchNodePlan, depth = 0): strin
178196 const lines : string [ ] = [ ] ;
179197 lines . push ( `${ indent ( depth ) } BatchFetch(service: "${ node . serviceName } ") {` ) ;
180198
181- for ( const alias of node . entityBatch . aliases ) {
199+ for ( let i = 0 ; i < node . entityBatch . aliases . length ; i ++ ) {
200+ const alias = node . entityBatch . aliases [ i ] ;
201+
182202 lines . push (
183203 `${ 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- ) ,
204+ `${ indent ( depth + 2 ) } paths: [` ,
205+ ...alias . paths . map ( path => `${ indent ( depth + 3 ) } "${ renderFlattenPath ( path ) } "` ) ,
189206 `${ indent ( depth + 2 ) } ]` ,
190- `${ indent ( depth + 2 ) } {` ,
191207 ) ;
208+
192209 const requires = renderSelectionSet ( alias . requires , depth + 3 ) ;
193- if ( requires ) lines . push ( requires ) ;
210+
211+ if ( requires ) {
212+ lines . push ( `${ indent ( depth + 2 ) } {` , requires , `${ indent ( depth + 2 ) } }` ) ;
213+ }
214+
215+ if ( i < node . entityBatch . aliases . length - 1 ) {
216+ lines . push ( `${ indent ( depth + 1 ) } }` ) ;
217+ }
218+ }
219+
220+ try {
194221 lines . push (
195- `${ indent ( depth + 2 ) } }` ,
196222 `${ indent ( depth + 1 ) } }` ,
197223 `${ indent ( depth + 1 ) } {` ,
198224 renderMultilineBlock (
199225 print ( parse ( node . operation ) ) . split ( '\n' ) . slice ( 1 , - 1 ) . join ( '\n' ) ,
200226 depth + 1 ,
201227 ) ,
202228 `${ indent ( depth + 1 ) } }` ,
229+ `${ indent ( depth ) } }` ,
203230 ) ;
231+ } catch {
232+ lines . push ( `${ indent ( depth + 1 ) } ${ node . operation } ` ) ;
204233 }
205- lines . push ( `${ indent ( depth ) } }` ) ;
206234
207235 return lines . join ( '\n' ) ;
208236}
@@ -597,7 +625,7 @@ function visitNode(
597625 ) ;
598626 break ;
599627
600- case 'Sequence' :
628+ case 'Sequence' : {
601629 result = null ;
602630
603631 let prevChild : QueryPlanNode | null = null ;
@@ -619,6 +647,7 @@ function visitNode(
619647 }
620648
621649 break ;
650+ }
622651
623652 case 'Parallel' :
624653 result . children = [ ] ;
0 commit comments