Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only compute ClientSideBaseVisitor's fragmentsGraph once, at instantiation time #10019

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
---

Only compute ClientSideBaseVisitor's fragmentsGraph once at instantiation time
n1ru4l marked this conversation as resolved.
Show resolved Hide resolved
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
Loading