dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.72k stars 1.31k forks source link

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

Closed vhfmag closed 2 weeks ago

vhfmag commented 2 weeks ago

Description

As mentioned in https://github.com/dotansimha/graphql-code-generator/issues/10018, ClientSideBaseVisitor's fragmentsGraph is implemented as a getter, despite not depending on anything that changes after the class is first instantiated. Turning fragmentsGraph into a static property improved build time from ~130s to ~50s in a big monorepo.

This PR does that and it makes field fragmentsGraph depends on (_fragments) read-only to make sure we don't break the assumption behind pre-computing the former.

Related: #10018

Type of change

Please delete options that are not relevant.

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

Test Environment:

Checklist:

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

changeset-bot[bot] commented 2 weeks ago

🦋 Changeset detected

Latest commit: 049b7224d4a666132e63f84c64c413a8cfe7f899

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages | Name | Type | | ------------------------------------------ | ----- | | @graphql-codegen/visitor-plugin-common | Patch | | @graphql-codegen/typescript-document-nodes | Patch | | @graphql-codegen/gql-tag-operations | Patch | | @graphql-codegen/typescript-operations | Patch | | @graphql-codegen/typescript-resolvers | Patch | | @graphql-codegen/typed-document-node | Patch | | @graphql-codegen/typescript | Patch | | @graphql-codegen/graphql-modules-preset | Patch | | @graphql-codegen/client-preset | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR