Skip to content

Commit

Permalink
Avoid unnecessarily importing isType from graphql package (apollo…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn authored Oct 4, 2021
1 parent b63a3f5 commit 7620b5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
[@benjamn](https://github.com/benjamn) in [#8862](https://github.com/apollographql/apollo-client/pull/8862)

- Avoid importing `isType` from the `graphql` package internally, to prevent bundlers from including as much as 3.4kB of unnecessary code. <br/>
[@benjamn](https://github.com/benjamn) in [#8891](https://github.com/apollographql/apollo-client/pull/8891)

## Apollo Client 3.4.15

### Bug Fixes
Expand Down
14 changes: 7 additions & 7 deletions src/utilities/globals/fix-graphql.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// The ordering of these imports is important, because it ensures the temporary
// process.env.NODE_ENV polyfill is defined globally (if necessary) before we
// import { isType } from 'graphql'. The instanceOf function that we really care
// import { Source } from 'graphql'. The instanceOf function that we really care
// about (the one that uses process.env.NODE_ENV) is not exported from the
// top-level graphql package, but isType uses instanceOf, and is exported.
// top-level graphql package, but graphql/language/source uses instanceOf, and
// has relatively few dependencies, so importing it here should not increase
// bundle sizes as much as other options.
import { remove } from 'ts-invariant/process';
import { isType } from 'graphql';
import { Source } from 'graphql';

export function removeTemporaryGlobals() {
// Calling isType here just to make sure it won't be tree-shaken away,
// provided applyFixes is called elsewhere.
isType(null);
return remove();
// Using Source here here just to make sure it won't be tree-shaken away.
return typeof Source === "function" ? remove() : remove();
}

0 comments on commit 7620b5b

Please sign in to comment.