diff --git a/CHANGELOG.md b/CHANGELOG.md index 393d5460bbc..ed8dd86abac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.
+ [@benjamn](https://github.com/benjamn) in [#8891](https://github.com/apollographql/apollo-client/pull/8891) + ## Apollo Client 3.4.15 ### Bug Fixes diff --git a/src/utilities/globals/fix-graphql.ts b/src/utilities/globals/fix-graphql.ts index c6ab391797f..15b6a69d089 100644 --- a/src/utilities/globals/fix-graphql.ts +++ b/src/utilities/globals/fix-graphql.ts @@ -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(); }