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

Avoid unnecessarily importing isType from graphql package #8891

Merged
merged 2 commits into from
Oct 4, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Oct 4, 2021

To import graphql (and its internal instanceOf function) for the first time with process.env.NODE_ENV safely polyfilled, PR #8347 selected a somewhat arbitrary export of the graphql package that uses instanceOf, specifically the isType function exported by graphql/type/definition.

As revealed by issue #8705, importing isType was a bad choice, since it depends on a bunch of other code within the graphql package, unnecessarily increasing minified+gzip bundle size by approximately 3.4kB.

A better choice is the Source constructor, which is already imported thanks to other necessary imports, and also imports/uses instanceOf.

To import `graphql` (and its internal `instanceOf` function) for the
first time with `process.env.NODE_ENV` safely polyfilled, PR #8347
selected a somewhat arbitrary export of the `graphql` package that uses
`instanceOf`, specifically the `isType` function exported by
`graphql/type/definition`.

As revealed by issue #8705, importing `isType` was a bad choice, since
it depends on a bunch of other code within the `graphql` package,
unnecessarily increasing minified+gzip bundle size by 3.4kB.

A better choice is the `Source` constructor, which is already imported
thanks to other necessary imports, and also imports/uses `instanceOf`.
Copy link
Contributor

@brainkim brainkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@benjamn benjamn merged commit 7620b5b into main Oct 4, 2021
@benjamn benjamn deleted the avoid-importing-isType-from-graphql branch October 4, 2021 21:45
@hwillson
Copy link
Member

hwillson commented Oct 4, 2021

Great find @benjamn - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apollo and graphql bundle size combined increases significantly
3 participants