@@ -54,6 +54,7 @@ function loadSiblings(baseDir: string, loadPaths: string[]): Source[] {
54
54
}
55
55
56
56
const operationsCache : Map < string , Source [ ] > = new Map ( ) ;
57
+ const siblingOperationsCache : Map < Source [ ] , SiblingOperations > = new Map ( ) ;
57
58
58
59
export function getSiblingOperations ( options : ParserOptions , gqlConfig : GraphQLConfig ) : SiblingOperations {
59
60
let siblings : Source [ ] | null = null ;
@@ -116,6 +117,13 @@ export function getSiblingOperations(options: ParserOptions, gqlConfig: GraphQLC
116
117
} ;
117
118
}
118
119
120
+ // Since the siblings array is cached, we can use it as cache key.
121
+ // We should get the same array reference each time we get
122
+ // to this point for the same graphql project
123
+ if ( siblingOperationsCache . has ( siblings ) ) {
124
+ return siblingOperationsCache . get ( siblings )
125
+ }
126
+
119
127
let fragmentsCache : FragmentSource [ ] | null = null ;
120
128
121
129
const getFragments = ( ) : FragmentSource [ ] => {
@@ -197,7 +205,7 @@ export function getSiblingOperations(options: ParserOptions, gqlConfig: GraphQLC
197
205
return collected ;
198
206
} ;
199
207
200
- return {
208
+ const siblingOperations = {
201
209
available : true ,
202
210
getFragments,
203
211
getOperations,
@@ -208,4 +216,6 @@ export function getSiblingOperations(options: ParserOptions, gqlConfig: GraphQLC
208
216
getOperationByType : type => getOperations ( ) . filter ( o => o . document . operation === type ) ,
209
217
getFragmentsInUse : ( selectable , recursive = true ) => Array . from ( collectFragments ( selectable , recursive ) . values ( ) ) ,
210
218
} ;
219
+ siblingOperationsCache . set ( siblings , siblingOperations )
220
+ return siblingOperations
211
221
}
0 commit comments