@@ -68,7 +68,7 @@ function resolveIdentifierToGraphQLCall(
6868 return checks . isGraphQLCall ( value , checker ) ? value : null ;
6969}
7070
71- function unrollFragment (
71+ export function unrollFragment (
7272 element : ts . Identifier ,
7373 info : ts . server . PluginCreateInfo ,
7474 checker : ts . TypeChecker | undefined
@@ -135,13 +135,16 @@ export function findAllCallExpressions(
135135 nodes : Array < {
136136 node : ts . StringLiteralLike ;
137137 schema : string | null ;
138+ // For gql.tada call-expressions, this contains the identifiers of explicitly declared fragments
139+ tadaFragmentRefs ?: readonly ts . Identifier [ ] | null ;
138140 } > ;
139141 fragments : Array < FragmentDefinitionNode > ;
140142} {
141143 const typeChecker = info . languageService . getProgram ( ) ?. getTypeChecker ( ) ;
142144 const result : Array < {
143145 node : ts . StringLiteralLike ;
144146 schema : string | null ;
147+ tadaFragmentRefs ?: readonly ts . Identifier [ ] ;
145148 } > = [ ] ;
146149 let fragments : Array < FragmentDefinitionNode > = [ ] ;
147150 let hasTriedToFindFragments = shouldSearchFragments ? false : true ;
@@ -160,18 +163,30 @@ export function findAllCallExpressions(
160163 const name = checks . getSchemaName ( node , typeChecker ) ;
161164 const text = node . arguments [ 0 ] ;
162165 const fragmentRefs = resolveTadaFragmentArray ( node . arguments [ 1 ] ) ;
166+ const isTadaCall = checks . isTadaGraphQLCall ( node , typeChecker ) ;
163167
164168 if ( ! hasTriedToFindFragments && ! fragmentRefs ) {
165- hasTriedToFindFragments = true ;
166- fragments . push ( ...getAllFragments ( sourceFile . fileName , node , info ) ) ;
169+ // Only collect global fragments if this is NOT a gql.tada call
170+ if ( ! isTadaCall ) {
171+ hasTriedToFindFragments = true ;
172+ fragments . push ( ...getAllFragments ( node , info ) ) ;
173+ }
167174 } else if ( fragmentRefs ) {
168175 for ( const identifier of fragmentRefs ) {
169176 fragments . push ( ...unrollFragment ( identifier , info , typeChecker ) ) ;
170177 }
171178 }
172179
173180 if ( text && ts . isStringLiteralLike ( text ) ) {
174- result . push ( { node : text , schema : name } ) ;
181+ result . push ( {
182+ node : text ,
183+ schema : name ,
184+ tadaFragmentRefs : isTadaCall
185+ ? fragmentRefs === undefined
186+ ? [ ]
187+ : fragmentRefs
188+ : undefined ,
189+ } ) ;
175190 }
176191 }
177192 find ( sourceFile ) ;
@@ -213,7 +228,6 @@ export function findAllPersistedCallExpressions(
213228}
214229
215230export function getAllFragments (
216- fileName : string ,
217231 node : ts . Node ,
218232 info : ts . server . PluginCreateInfo
219233) {
0 commit comments