From 1b8656fa3577e5568af4ce5d6aadbbb6384658fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Magalh=C3=A3es?= Date: Fri, 21 Jun 2024 18:39:48 +0000 Subject: [PATCH 1/3] feat: Pre-compute ClientSideBaseVisitor's fragmentsGraph --- .../visitor-plugin-common/src/client-side-base-visitor.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts index 5dbad1f4536..696d7b14382 100644 --- a/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts @@ -251,7 +251,8 @@ export class ClientSideBaseVisitor< private _onExecutableDocumentNode?: Unstable_OnExecutableDocumentNode; private _omitDefinitions?: boolean; - private _fragments: Map; + private readonly _fragments: ReadonlyMap; + private readonly fragmentsGraph: DepGraph; constructor( protected _schema: GraphQLSchema, @@ -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); } @@ -519,7 +521,7 @@ export class ClientSideBaseVisitor< )};`; } - private get fragmentsGraph(): DepGraph { + private _getFragmentsGraph(): DepGraph { const graph = new DepGraph({ circular: true }); for (const fragment of this._fragments.values()) { From cbf1d360e7a8ea57c23f26d98b39ba58bc5a0c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Magalh=C3=A3es?= Date: Fri, 21 Jun 2024 20:39:17 +0000 Subject: [PATCH 2/3] chore: changeset --- .changeset/rotten-eels-eat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rotten-eels-eat.md diff --git a/.changeset/rotten-eels-eat.md b/.changeset/rotten-eels-eat.md new file mode 100644 index 00000000000..ae941de8f9c --- /dev/null +++ b/.changeset/rotten-eels-eat.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/visitor-plugin-common': patch +--- + +Only compute ClientSideBaseVisitor's fragmentsGraph once at instantiation time From 049b7224d4a666132e63f84c64c413a8cfe7f899 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Mon, 24 Jun 2024 10:25:54 +0200 Subject: [PATCH 3/3] Update .changeset/rotten-eels-eat.md --- .changeset/rotten-eels-eat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/rotten-eels-eat.md b/.changeset/rotten-eels-eat.md index ae941de8f9c..7edd8743d33 100644 --- a/.changeset/rotten-eels-eat.md +++ b/.changeset/rotten-eels-eat.md @@ -2,4 +2,4 @@ '@graphql-codegen/visitor-plugin-common': patch --- -Only compute ClientSideBaseVisitor's fragmentsGraph once at instantiation time +Improve code generation performance by computing `ClientSideBaseVisitor`'s `fragmentsGraph` once at instantiation time.