Skip to content

Commit 14ce39e

Browse files
vhfmagn1ru4l
andauthored
Only compute ClientSideBaseVisitor's fragmentsGraph once, at instantiation time (#10019)
* feat: Pre-compute ClientSideBaseVisitor's fragmentsGraph * chore: changeset * Update .changeset/rotten-eels-eat.md --------- Co-authored-by: Victor Magalhães <[email protected]> Co-authored-by: Laurin Quast <[email protected]>
1 parent 9af9ce2 commit 14ce39e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/rotten-eels-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/visitor-plugin-common': patch
3+
---
4+
5+
Improve code generation performance by computing `ClientSideBaseVisitor`'s `fragmentsGraph` once at instantiation time.

packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export class ClientSideBaseVisitor<
251251

252252
private _onExecutableDocumentNode?: Unstable_OnExecutableDocumentNode;
253253
private _omitDefinitions?: boolean;
254-
private _fragments: Map<string, LoadedFragment>;
254+
private readonly _fragments: ReadonlyMap<string, LoadedFragment>;
255+
private readonly fragmentsGraph: DepGraph<LoadedFragment>;
255256

256257
constructor(
257258
protected _schema: GraphQLSchema,
@@ -289,6 +290,7 @@ export class ClientSideBaseVisitor<
289290
this._onExecutableDocumentNode = (rawConfig as any).unstable_onExecutableDocumentNode;
290291
this._omitDefinitions = (rawConfig as any).unstable_omitDefinitions;
291292
this._fragments = new Map(fragments.map(fragment => [fragment.name, fragment]));
293+
this.fragmentsGraph = this._getFragmentsGraph();
292294
autoBind(this);
293295
}
294296

@@ -519,7 +521,7 @@ export class ClientSideBaseVisitor<
519521
)};`;
520522
}
521523

522-
private get fragmentsGraph(): DepGraph<LoadedFragment> {
524+
private _getFragmentsGraph(): DepGraph<LoadedFragment> {
523525
const graph = new DepGraph<LoadedFragment>({ circular: true });
524526

525527
for (const fragment of this._fragments.values()) {

0 commit comments

Comments
 (0)