Skip to content

Commit

Permalink
Only compute ClientSideBaseVisitor's fragmentsGraph once, at inst…
Browse files Browse the repository at this point in the history
…antiation time (#10019)

* feat: Pre-compute ClientSideBaseVisitor's fragmentsGraph

* chore: changeset

* Update .changeset/rotten-eels-eat.md

---------

Co-authored-by: Victor Magalhães <vhfmag@users.noreply.github.com>
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent 9af9ce2 commit 14ce39e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-eels-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/visitor-plugin-common': patch
---

Improve code generation performance by computing `ClientSideBaseVisitor`'s `fragmentsGraph` once at instantiation time.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ export class ClientSideBaseVisitor<

private _onExecutableDocumentNode?: Unstable_OnExecutableDocumentNode;
private _omitDefinitions?: boolean;
private _fragments: Map<string, LoadedFragment>;
private readonly _fragments: ReadonlyMap<string, LoadedFragment>;
private readonly fragmentsGraph: DepGraph<LoadedFragment>;

constructor(
protected _schema: GraphQLSchema,
Expand Down Expand Up @@ -289,6 +290,7 @@ export class ClientSideBaseVisitor<
this._onExecutableDocumentNode = (rawConfig as any).unstable_onExecutableDocumentNode;
this._omitDefinitions = (rawConfig as any).unstable_omitDefinitions;
this._fragments = new Map(fragments.map(fragment => [fragment.name, fragment]));
this.fragmentsGraph = this._getFragmentsGraph();
autoBind(this);
}

Expand Down Expand Up @@ -519,7 +521,7 @@ export class ClientSideBaseVisitor<
)};`;
}

private get fragmentsGraph(): DepGraph<LoadedFragment> {
private _getFragmentsGraph(): DepGraph<LoadedFragment> {
const graph = new DepGraph<LoadedFragment>({ circular: true });

for (const fragment of this._fragments.values()) {
Expand Down

0 comments on commit 14ce39e

Please sign in to comment.