diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45d47f29beb..13ff576fa9b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,12 +7,14 @@
### Bug Fixes
-- Fix ObservableQuery.getCurrentResult() returning cached data with certain fetch policies.
+- Fix `ObservableQuery.getCurrentResult()` returning cached `data` with certain fetch policies.
[@brainkim](https://github.com/brainkim) in [#8718](https://github.com/apollographql/apollo-client/pull/8718)
- Prevent `ssrMode`/`ssrForceFetchDelay` from causing queries to hang.
[@brainkim](https://github.com/brainkim) in [#8709](https://github.com/apollographql/apollo-client/pull/8709)
+- Import `@apollo/client/utilities/globals` internally wherever `__DEV__` is used, not just in `@apollo/client/**/index.js` entry points.
+ [@benjamn](https://github.com/benjamn) in [#8720](https://github.com/apollographql/apollo-client/pull/8720)
## Apollo Client 3.4.9
diff --git a/config/checkDEV.ts b/config/checkDEV.ts
deleted file mode 100644
index 705f41ffa95..00000000000
--- a/config/checkDEV.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import * as path from "path";
-import { readFileSync, promises as fs } from "fs";
-import { eachFile, distDir } from "./helpers";
-
-const entryPoints = require("./entryPoints.js");
-
-const filesWithDEV = new Set();
-
-eachFile(distDir, async file => {
- const source = await fs.readFile(file, "utf8");
- if (/\b__DEV__\b/.test(source)) {
- filesWithDEV.add(file);
- }
-}).then(() => {
- const filesByEntryPoint = new Map;
- }>();
-
- entryPoints.forEach(({ dirs }: { dirs: string[] }) => {
- const relIndexPath = path.join(...dirs, "index.js");
- const absIndexPath = path.join(distDir, relIndexPath);
- filesByEntryPoint.set(dirs.join("/"), {
- indexPath: relIndexPath,
- source: readFileSync(absIndexPath, "utf8"),
- files: new Set(),
- });
- });
-
- filesWithDEV.forEach(file => {
- const entryPointDir = entryPoints.getEntryPointDirectory(file);
- const info = filesByEntryPoint.get(entryPointDir);
- const absEntryPointDir = path.join(distDir, entryPointDir);
- const relPath = "./" + path.relative(absEntryPointDir, file);
- if (info) {
- info.files.add(relPath);
- }
- });
-
- filesByEntryPoint.forEach(({ indexPath, source, files }, entryPointDir) => {
- if (!files.size || source.indexOf("checkDEV()") >= 0) {
- return;
- }
- const entryPointId = `@apollo/client/${entryPointDir}`;
- throw new Error(`Entry point ${
- entryPointId
- }/index.js does not call checkDEV(), but ${
- entryPointId
- } contains the following files that use __DEV__: ${
- Array.from(files).join(", ")
- }`);
- });
-});
diff --git a/config/entryPoints.js b/config/entryPoints.js
index 809ecc251ef..471cad11461 100644
--- a/config/entryPoints.js
+++ b/config/entryPoints.js
@@ -22,10 +22,8 @@ const entryPoints = [
{ dirs: ['react', 'hooks'] },
{ dirs: ['react', 'parser'] },
{ dirs: ['react', 'ssr'] },
- { dirs: ['utilities'],
- sideEffects: [
- "./globals/**"
- ]},
+ { dirs: ['utilities'] },
+ { dirs: ['utilities', 'globals'], sideEffects: true },
{ dirs: ['testing'], extensions: [".js", ".jsx"] },
];
diff --git a/config/resolveModuleIds.ts b/config/resolveModuleIds.ts
index 061fd7a4826..d0c43cb1305 100644
--- a/config/resolveModuleIds.ts
+++ b/config/resolveModuleIds.ts
@@ -6,7 +6,32 @@ import { distDir, eachFile, reparse, reprint } from './helpers';
eachFile(distDir, (file, relPath) => new Promise((resolve, reject) => {
fs.readFile(file, "utf8", (error, source) => {
if (error) return reject(error);
- const output = transform(source, file);
+
+ const tr = new Transformer;
+ const output = tr.transform(source, file);
+
+ if (
+ /\b__DEV__\b/.test(source) &&
+ // Ignore modules that reside within @apollo/client/utilities/globals.
+ !relPath.startsWith("utilities/globals/")
+ ) {
+ let importsUtilitiesGlobals = false;
+
+ tr.absolutePaths.forEach(absPath => {
+ const distRelativePath =
+ path.relative(distDir, absPath).split(path.sep).join("/");
+ if (distRelativePath === "utilities/globals/index.js") {
+ importsUtilitiesGlobals = true;
+ }
+ });
+
+ if (!importsUtilitiesGlobals) {
+ reject(new Error(`Module ${
+ relPath
+ } uses __DEV__ but does not import @apollo/client/utilities/globals`));
+ }
+ }
+
if (source === output) {
resolve(file);
} else {
@@ -21,61 +46,67 @@ import * as recast from "recast";
const n = recast.types.namedTypes;
type Node = recast.types.namedTypes.Node;
-function transform(code: string, file: string) {
- const ast = reparse(code);
-
- recast.visit(ast, {
- visitImportDeclaration(path) {
- this.traverse(path);
- normalizeSourceString(file, path.node.source);
- },
-
- visitImportExpression(path) {
- this.traverse(path);
- normalizeSourceString(file, path.node.source);
- },
-
- visitExportAllDeclaration(path) {
- this.traverse(path);
- normalizeSourceString(file, path.node.source);
- },
-
- visitExportNamedDeclaration(path) {
- this.traverse(path);
- normalizeSourceString(file, path.node.source);
- },
- });
+class Transformer {
+ absolutePaths = new Set();
- return reprint(ast);
-}
+ transform(code: string, file: string) {
+ const ast = reparse(code);
+ const transformer = this;
-function isRelative(id: string) {
- return id.startsWith("./") || id.startsWith("../");
-}
+ recast.visit(ast, {
+ visitImportDeclaration(path) {
+ this.traverse(path);
+ transformer.normalizeSourceString(file, path.node.source);
+ },
-function normalizeSourceString(file: string, source?: Node | null) {
- if (source && n.StringLiteral.check(source) && isRelative(source.value)) {
- try {
- source.value = normalizeId(source.value, file);
- } catch (error) {
- console.error(`Failed to resolve ${source.value} in ${file}`);
- process.exit(1);
+ visitImportExpression(path) {
+ this.traverse(path);
+ transformer.normalizeSourceString(file, path.node.source);
+ },
+
+ visitExportAllDeclaration(path) {
+ this.traverse(path);
+ transformer.normalizeSourceString(file, path.node.source);
+ },
+
+ visitExportNamedDeclaration(path) {
+ this.traverse(path);
+ transformer.normalizeSourceString(file, path.node.source);
+ },
+ });
+
+ return reprint(ast);
+ }
+
+ isRelative(id: string) {
+ return id.startsWith("./") || id.startsWith("../");
+ }
+
+ normalizeSourceString(file: string, source: Node | null | undefined) {
+ if (source && n.StringLiteral.check(source) && this.isRelative(source.value)) {
+ try {
+ source.value = this.normalizeId(source.value, file);
+ } catch (error) {
+ console.error(`Failed to resolve ${source.value} in ${file}`);
+ process.exit(1);
+ }
}
}
-}
-function normalizeId(id: string, file: string) {
- const basedir = path.dirname(file);
- const absPath = resolve.sync(id, {
- basedir,
- packageFilter(pkg) {
- return pkg.module ? {
- ...pkg,
- main: pkg.module,
- } : pkg;
- },
- });
- const relPath = path.relative(basedir, absPath);
- const relId = relPath.split(path.sep).join('/');
- return isRelative(relId) ? relId : "./" + relId;
+ normalizeId(id: string, file: string) {
+ const basedir = path.dirname(file);
+ const absPath = resolve.sync(id, {
+ basedir,
+ packageFilter(pkg) {
+ return pkg.module ? {
+ ...pkg,
+ main: pkg.module,
+ } : pkg;
+ },
+ });
+ this.absolutePaths.add(absPath);
+ const relPath = path.relative(basedir, absPath);
+ const relId = relPath.split(path.sep).join('/');
+ return this.isRelative(relId) ? relId : "./" + relId;
+ }
}
diff --git a/package.json b/package.json
index e3db772c799..80d336b8055 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
"scripts": {
"prebuild": "npm run clean",
"build": "tsc",
- "postbuild": "npm run update-version && npm run invariants && npm run sourcemaps && npm run rollup && npm run prepdist && npm run resolve && npm run check-DEV && npm run verify-version",
+ "postbuild": "npm run update-version && npm run invariants && npm run sourcemaps && npm run rollup && npm run prepdist && npm run resolve && npm run verify-version",
"update-version": "node config/version.js update",
"verify-version": "node config/version.js verify",
"invariants": "ts-node-script config/processInvariants.ts",
@@ -39,7 +39,6 @@
"rollup": "rollup -c ./config/rollup.config.js",
"prepdist": "node ./config/prepareDist.js",
"resolve": "ts-node-script config/resolveModuleIds.ts",
- "check-DEV": "ts-node-script config/checkDEV.ts",
"clean": "rimraf -r dist coverage lib",
"test": "jest --config ./config/jest.config.js",
"test:debug": "BABEL_ENV=server node --inspect-brk node_modules/.bin/jest --config ./config/jest.config.js --runInBand",
diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap
index c4d08899bb5..f4dbb7e893a 100644
--- a/src/__tests__/__snapshots__/exports.ts.snap
+++ b/src/__tests__/__snapshots__/exports.ts.snap
@@ -331,7 +331,6 @@ Array [
"buildQueryFromSelectionSet",
"canUseWeakMap",
"canUseWeakSet",
- "checkDEV",
"checkDocument",
"cloneDeep",
"compact",
@@ -381,3 +380,14 @@ Array [
"valueToObjectRepresentation",
]
`;
+
+exports[`exports of public entry points @apollo/client/utilities/globals 1`] = `
+Array [
+ "DEV",
+ "InvariantError",
+ "checkDEV",
+ "global",
+ "invariant",
+ "maybe",
+]
+`;
diff --git a/src/__tests__/exports.ts b/src/__tests__/exports.ts
index 13e00747a14..7d521de8d42 100644
--- a/src/__tests__/exports.ts
+++ b/src/__tests__/exports.ts
@@ -23,6 +23,7 @@ import * as reactParser from "../react/parser";
import * as reactSSR from "../react/ssr";
import * as testing from "../testing";
import * as utilities from "../utilities";
+import * as utilitiesGlobals from "../utilities/globals";
const entryPoints = require("../../config/entryPoints.js");
@@ -63,6 +64,7 @@ describe('exports of public entry points', () => {
check("@apollo/client/react/ssr", reactSSR);
check("@apollo/client/testing", testing);
check("@apollo/client/utilities", utilities);
+ check("@apollo/client/utilities/globals", utilitiesGlobals);
it("completeness", () => {
const { join } = require("path").posix;
diff --git a/src/cache/index.ts b/src/cache/index.ts
index f88a9510206..9207cf33fd9 100644
--- a/src/cache/index.ts
+++ b/src/cache/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../utilities";
-checkDEV();
+import '../utilities/globals';
export { Transaction, ApolloCache } from './core/cache';
export { Cache } from './core/types/Cache';
diff --git a/src/cache/inmemory/entityStore.ts b/src/cache/inmemory/entityStore.ts
index ff7c6f62bec..486324f4595 100644
--- a/src/cache/inmemory/entityStore.ts
+++ b/src/cache/inmemory/entityStore.ts
@@ -1,5 +1,5 @@
+import { invariant } from '../../utilities/globals';
import { dep, OptimisticDependencyFunction } from 'optimism';
-import { invariant } from 'ts-invariant';
import { equal } from '@wry/equality';
import { Trie } from '@wry/trie';
diff --git a/src/cache/inmemory/object-canon.ts b/src/cache/inmemory/object-canon.ts
index c6b96d1ba2e..9480d537f9a 100644
--- a/src/cache/inmemory/object-canon.ts
+++ b/src/cache/inmemory/object-canon.ts
@@ -1,3 +1,5 @@
+import "../../utilities/globals";
+
import { Trie } from "@wry/trie";
import {
canUseWeakMap,
diff --git a/src/cache/inmemory/policies.ts b/src/cache/inmemory/policies.ts
index 399f7c2fbe5..9354517c820 100644
--- a/src/cache/inmemory/policies.ts
+++ b/src/cache/inmemory/policies.ts
@@ -1,3 +1,5 @@
+import { invariant, InvariantError } from '../../utilities/globals';
+
import {
InlineFragmentNode,
FragmentDefinitionNode,
@@ -6,7 +8,6 @@ import {
} from 'graphql';
import { Trie } from '@wry/trie';
-import { invariant, InvariantError } from 'ts-invariant';
import {
FragmentMap,
diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts
index 81a9b585ef9..79ccf818fb8 100644
--- a/src/cache/inmemory/readFromStore.ts
+++ b/src/cache/inmemory/readFromStore.ts
@@ -1,10 +1,11 @@
+import { invariant, InvariantError } from '../../utilities/globals';
+
import {
DocumentNode,
FieldNode,
SelectionSetNode,
} from 'graphql';
import { wrap, OptimisticWrapperFunction } from 'optimism';
-import { invariant, InvariantError } from 'ts-invariant';
import {
isField,
diff --git a/src/cache/inmemory/writeToStore.ts b/src/cache/inmemory/writeToStore.ts
index eb20fa86344..06e2acabc42 100644
--- a/src/cache/inmemory/writeToStore.ts
+++ b/src/cache/inmemory/writeToStore.ts
@@ -1,5 +1,6 @@
+import { invariant, InvariantError } from '../../utilities/globals';
+
import { SelectionSetNode, FieldNode, SelectionNode } from 'graphql';
-import { invariant, InvariantError } from 'ts-invariant';
import { equal } from '@wry/equality';
import {
diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts
index cf61b920c43..4cead14748f 100644
--- a/src/core/ApolloClient.ts
+++ b/src/core/ApolloClient.ts
@@ -1,5 +1,6 @@
+import { invariant, InvariantError } from '../utilities/globals';
+
import { ExecutionResult, DocumentNode } from 'graphql';
-import { invariant, InvariantError } from 'ts-invariant';
import { ApolloLink, FetchResult, GraphQLRequest, execute } from '../link/core';
import { ApolloCache, DataProxy } from '../cache';
diff --git a/src/core/LocalState.ts b/src/core/LocalState.ts
index e21226e0e8a..e6e9518016b 100644
--- a/src/core/LocalState.ts
+++ b/src/core/LocalState.ts
@@ -1,3 +1,5 @@
+import { invariant } from '../utilities/globals';
+
import {
DocumentNode,
OperationDefinitionNode,
@@ -10,7 +12,6 @@ import {
visit,
BREAK,
} from 'graphql';
-import { invariant } from 'ts-invariant';
import { ApolloCache } from '../cache';
import {
diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts
index 44287fc0d34..6171e3f44fa 100644
--- a/src/core/ObservableQuery.ts
+++ b/src/core/ObservableQuery.ts
@@ -1,4 +1,5 @@
-import { invariant } from 'ts-invariant';
+import { invariant } from '../utilities/globals';
+
import { equal } from '@wry/equality';
import { NetworkStatus, isNetworkRequestInFlight } from './networkStatus';
diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts
index 09e6c5f819c..312ca8eb4a9 100644
--- a/src/core/QueryManager.ts
+++ b/src/core/QueryManager.ts
@@ -1,5 +1,6 @@
+import { invariant, InvariantError } from '../utilities/globals';
+
import { DocumentNode } from 'graphql';
-import { invariant, InvariantError } from 'ts-invariant';
import { equal } from '@wry/equality';
import { ApolloLink, execute, FetchResult } from '../link/core';
diff --git a/src/core/index.ts b/src/core/index.ts
index 13c8744f273..7a48e7f39af 100644
--- a/src/core/index.ts
+++ b/src/core/index.ts
@@ -1,7 +1,6 @@
/* Core */
-import { DEV, checkDEV } from "../utilities";
-checkDEV();
+import { DEV } from '../utilities/globals';
export {
ApolloClient,
diff --git a/src/errors/index.ts b/src/errors/index.ts
index 03542d7b40c..333ae2853a3 100644
--- a/src/errors/index.ts
+++ b/src/errors/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../utilities";
-checkDEV();
+import '../utilities/globals';
import { GraphQLError } from 'graphql';
diff --git a/src/link/core/ApolloLink.ts b/src/link/core/ApolloLink.ts
index 74483ab16fb..4fdc9e02f6e 100644
--- a/src/link/core/ApolloLink.ts
+++ b/src/link/core/ApolloLink.ts
@@ -1,4 +1,4 @@
-import { InvariantError, invariant } from 'ts-invariant';
+import { InvariantError, invariant } from '../../utilities/globals';
import { Observable } from '../../utilities';
import {
diff --git a/src/link/core/index.ts b/src/link/core/index.ts
index 90047fbb6e0..6637331b2fa 100644
--- a/src/link/core/index.ts
+++ b/src/link/core/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export { empty } from './empty';
export { from } from './from';
diff --git a/src/link/http/checkFetcher.ts b/src/link/http/checkFetcher.ts
index 22724205c5a..4a58881a6c0 100644
--- a/src/link/http/checkFetcher.ts
+++ b/src/link/http/checkFetcher.ts
@@ -1,4 +1,4 @@
-import { InvariantError } from 'ts-invariant';
+import { InvariantError } from '../../utilities/globals';
export const checkFetcher = (fetcher: WindowOrWorkerGlobalScope['fetch'] | undefined) => {
if (!fetcher && typeof fetch === 'undefined') {
diff --git a/src/link/http/createHttpLink.ts b/src/link/http/createHttpLink.ts
index 6282377a948..7a386109728 100644
--- a/src/link/http/createHttpLink.ts
+++ b/src/link/http/createHttpLink.ts
@@ -1,3 +1,5 @@
+import '../../utilities/globals';
+
import { visit, DefinitionNode, VariableDefinitionNode } from 'graphql';
import { ApolloLink } from '../core';
diff --git a/src/link/http/index.ts b/src/link/http/index.ts
index d7110fa09e3..fa1800c5b40 100644
--- a/src/link/http/index.ts
+++ b/src/link/http/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export {
parseAndCheckHttpResponse,
diff --git a/src/link/http/serializeFetchParameter.ts b/src/link/http/serializeFetchParameter.ts
index f127e36b5b3..85de32e6a6a 100644
--- a/src/link/http/serializeFetchParameter.ts
+++ b/src/link/http/serializeFetchParameter.ts
@@ -1,4 +1,4 @@
-import { InvariantError } from 'ts-invariant';
+import { InvariantError } from '../../utilities/globals';
export type ClientParseError = InvariantError & {
parseError: Error;
diff --git a/src/link/persisted-queries/index.ts b/src/link/persisted-queries/index.ts
index 2e57399d945..abff1c06db1 100644
--- a/src/link/persisted-queries/index.ts
+++ b/src/link/persisted-queries/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import { invariant } from '../../utilities/globals';
import { print } from 'graphql';
import {
@@ -7,7 +6,6 @@ import {
ExecutionResult,
GraphQLError,
} from 'graphql';
-import { invariant } from 'ts-invariant';
import { ApolloLink, Operation } from '../core';
import { Observable, Observer, compact } from '../../utilities';
diff --git a/src/link/utils/index.ts b/src/link/utils/index.ts
index e06e5a3abe3..db089bdfda1 100644
--- a/src/link/utils/index.ts
+++ b/src/link/utils/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export { fromError } from './fromError';
export { toPromise } from './toPromise';
diff --git a/src/link/utils/toPromise.ts b/src/link/utils/toPromise.ts
index 5752348dee5..505de89ec75 100644
--- a/src/link/utils/toPromise.ts
+++ b/src/link/utils/toPromise.ts
@@ -1,5 +1,4 @@
-import { invariant } from 'ts-invariant';
-
+import { invariant } from '../../utilities/globals';
import { Observable } from '../../utilities';
export function toPromise(observable: Observable): Promise {
diff --git a/src/link/utils/validateOperation.ts b/src/link/utils/validateOperation.ts
index 61e1b855430..a269776111a 100644
--- a/src/link/utils/validateOperation.ts
+++ b/src/link/utils/validateOperation.ts
@@ -1,5 +1,4 @@
-import { InvariantError } from 'ts-invariant';
-
+import { InvariantError } from '../../utilities/globals'
import { GraphQLRequest } from '../core';
export function validateOperation(operation: GraphQLRequest): GraphQLRequest {
diff --git a/src/react/context/ApolloConsumer.tsx b/src/react/context/ApolloConsumer.tsx
index c6ba6fffdc2..02b8924806e 100644
--- a/src/react/context/ApolloConsumer.tsx
+++ b/src/react/context/ApolloConsumer.tsx
@@ -1,5 +1,6 @@
+import { invariant } from '../../utilities/globals';
+
import * as React from 'react';
-import { invariant } from 'ts-invariant';
import { ApolloClient } from '../../core';
import { getApolloContext } from './ApolloContext';
diff --git a/src/react/context/ApolloProvider.tsx b/src/react/context/ApolloProvider.tsx
index 5f678db8c91..b05215da0c2 100644
--- a/src/react/context/ApolloProvider.tsx
+++ b/src/react/context/ApolloProvider.tsx
@@ -1,5 +1,6 @@
+import { invariant } from '../../utilities/globals';
+
import * as React from 'react';
-import { invariant } from 'ts-invariant';
import { ApolloClient } from '../../core';
import { getApolloContext } from './ApolloContext';
diff --git a/src/react/context/index.ts b/src/react/context/index.ts
index 64a3908792a..0704a956b28 100644
--- a/src/react/context/index.ts
+++ b/src/react/context/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export * from './ApolloConsumer';
export * from './ApolloContext';
diff --git a/src/react/data/OperationData.ts b/src/react/data/OperationData.ts
index f6f6584ba8c..1af62dc4077 100644
--- a/src/react/data/OperationData.ts
+++ b/src/react/data/OperationData.ts
@@ -1,6 +1,7 @@
+import { invariant } from '../../utilities/globals';
+
import { DocumentNode } from 'graphql';
import { equal } from '@wry/equality';
-import { invariant } from 'ts-invariant';
import { ApolloClient } from '../../core';
import { DocumentType, parser, operationName } from '../parser';
diff --git a/src/react/data/index.ts b/src/react/data/index.ts
index 9da77854854..47324d8dad7 100644
--- a/src/react/data/index.ts
+++ b/src/react/data/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export { SubscriptionData } from './SubscriptionData';
export { OperationData } from './OperationData';
diff --git a/src/react/hoc/hoc-utils.tsx b/src/react/hoc/hoc-utils.tsx
index 58266adcc3a..18b4bc9f28b 100644
--- a/src/react/hoc/hoc-utils.tsx
+++ b/src/react/hoc/hoc-utils.tsx
@@ -1,5 +1,5 @@
+import { invariant } from '../../utilities/globals';
import * as React from 'react';
-import { invariant } from 'ts-invariant';
import { OperationVariables } from '../../core';
import { IDocumentDefinition } from '../parser';
diff --git a/src/react/hoc/index.ts b/src/react/hoc/index.ts
index 00f41e66d05..0fdfbf9e0ea 100644
--- a/src/react/hoc/index.ts
+++ b/src/react/hoc/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export { graphql } from './graphql';
diff --git a/src/react/hoc/withApollo.tsx b/src/react/hoc/withApollo.tsx
index 15fa8db2b27..d27dfcb1bf9 100644
--- a/src/react/hoc/withApollo.tsx
+++ b/src/react/hoc/withApollo.tsx
@@ -1,6 +1,6 @@
+import { invariant } from '../../utilities/globals';
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
-import { invariant } from 'ts-invariant';
import { ApolloConsumer } from '../context';
import { OperationOption, WithApolloClient } from './types';
diff --git a/src/react/hooks/index.ts b/src/react/hooks/index.ts
index 6d876cfea4d..c28017697fb 100644
--- a/src/react/hooks/index.ts
+++ b/src/react/hooks/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import '../../utilities/globals';
export * from './useApolloClient';
export * from './useLazyQuery';
diff --git a/src/react/hooks/useApolloClient.ts b/src/react/hooks/useApolloClient.ts
index 461635cab7f..670903da394 100644
--- a/src/react/hooks/useApolloClient.ts
+++ b/src/react/hooks/useApolloClient.ts
@@ -1,5 +1,6 @@
+import { invariant } from '../../utilities/globals';
+
import * as React from 'react';
-import { invariant } from 'ts-invariant';
import { ApolloClient } from '../../core';
import { getApolloContext } from '../context';
diff --git a/src/react/hooks/useSubscription.ts b/src/react/hooks/useSubscription.ts
index d0febf7d904..631591865f9 100644
--- a/src/react/hooks/useSubscription.ts
+++ b/src/react/hooks/useSubscription.ts
@@ -1,3 +1,5 @@
+import '../../utilities/globals';
+
import { useContext, useState, useRef, useEffect, useReducer } from 'react';
import { DocumentNode } from 'graphql';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
diff --git a/src/react/hooks/utils/useAfterFastRefresh.ts b/src/react/hooks/utils/useAfterFastRefresh.ts
index de8742f398e..da83b649636 100644
--- a/src/react/hooks/utils/useAfterFastRefresh.ts
+++ b/src/react/hooks/utils/useAfterFastRefresh.ts
@@ -1,3 +1,4 @@
+import '../../../utilities/globals';
import { useEffect, useRef } from "react";
/**
diff --git a/src/react/hooks/utils/useBaseQuery.ts b/src/react/hooks/utils/useBaseQuery.ts
index 48f5419dd4f..5ab114a9902 100644
--- a/src/react/hooks/utils/useBaseQuery.ts
+++ b/src/react/hooks/utils/useBaseQuery.ts
@@ -1,3 +1,5 @@
+import '../../../utilities/globals';
+
import { useContext, useEffect, useReducer, useRef } from 'react';
import { DocumentNode } from 'graphql';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
diff --git a/src/react/index.ts b/src/react/index.ts
index deab19a3cd3..769c0cfddc9 100644
--- a/src/react/index.ts
+++ b/src/react/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../utilities";
-checkDEV();
+import '../utilities/globals';
export {
ApolloProvider,
diff --git a/src/react/parser/index.ts b/src/react/parser/index.ts
index 6a43a8d5853..c9832e034a2 100644
--- a/src/react/parser/index.ts
+++ b/src/react/parser/index.ts
@@ -1,5 +1,4 @@
-import { checkDEV } from "../../utilities";
-checkDEV();
+import { invariant } from '../../utilities/globals';
import {
DocumentNode,
@@ -7,7 +6,6 @@ import {
VariableDefinitionNode,
OperationDefinitionNode
} from 'graphql';
-import { invariant } from 'ts-invariant';
export enum DocumentType {
Query,
diff --git a/src/testing/index.ts b/src/testing/index.ts
index 029df077cad..b6040c34513 100644
--- a/src/testing/index.ts
+++ b/src/testing/index.ts
@@ -1,4 +1,2 @@
-import { checkDEV } from "../utilities";
-checkDEV();
-
+import '../utilities/globals';
export * from '../utilities/testing';
diff --git a/src/utilities/globals/DEV.ts b/src/utilities/globals/DEV.ts
index 04ad1a11958..540f64813cf 100644
--- a/src/utilities/globals/DEV.ts
+++ b/src/utilities/globals/DEV.ts
@@ -1,5 +1,5 @@
-import global from "../common/global";
-import { maybe } from "../common/maybe";
+import global from "./global";
+import { maybe } from "./maybe";
// To keep string-based find/replace minifiers from messing with __DEV__ inside
// string literals or properties like global.__DEV__, we construct the "__DEV__"
diff --git a/src/utilities/common/global.ts b/src/utilities/globals/global.ts
similarity index 100%
rename from src/utilities/common/global.ts
rename to src/utilities/globals/global.ts
diff --git a/src/utilities/globals/index.ts b/src/utilities/globals/index.ts
index cb481e245b7..92adae0ae32 100644
--- a/src/utilities/globals/index.ts
+++ b/src/utilities/globals/index.ts
@@ -1,4 +1,4 @@
-import { invariant } from "ts-invariant";
+import { invariant, InvariantError } from "ts-invariant";
// Just in case the graphql package switches from process.env.NODE_ENV to
// __DEV__, make sure __DEV__ is polyfilled before importing graphql.
@@ -11,8 +11,11 @@ export function checkDEV() {
// Import graphql/jsutils/instanceOf safely, working around its unchecked usage
// of process.env.NODE_ENV and https://github.com/graphql/graphql-js/pull/2894.
import { removeTemporaryGlobals } from "./graphql";
-export { removeTemporaryGlobals }
// Synchronously undo the global process.env.NODE_ENV polyfill that we created
// temporarily while importing the offending graphql/jsutils/instanceOf module.
removeTemporaryGlobals();
+
+export { maybe } from "./maybe";
+export { default as global } from "./global";
+export { invariant, InvariantError }
diff --git a/src/utilities/common/maybe.ts b/src/utilities/globals/maybe.ts
similarity index 100%
rename from src/utilities/common/maybe.ts
rename to src/utilities/globals/maybe.ts
diff --git a/src/utilities/graphql/directives.ts b/src/utilities/graphql/directives.ts
index 2099e791c03..76c36b08083 100644
--- a/src/utilities/graphql/directives.ts
+++ b/src/utilities/graphql/directives.ts
@@ -1,3 +1,5 @@
+import { invariant } from '../globals';
+
// Provides the methods that allow QueryManager to handle the `skip` and
// `include` directives within GraphQL.
import {
@@ -12,8 +14,6 @@ import {
visit,
} from 'graphql';
-import { invariant } from 'ts-invariant';
-
export type DirectiveInfo = {
[fieldName: string]: { [argName: string]: any };
};
diff --git a/src/utilities/graphql/fragments.ts b/src/utilities/graphql/fragments.ts
index f1ee36de858..f6ce8f07008 100644
--- a/src/utilities/graphql/fragments.ts
+++ b/src/utilities/graphql/fragments.ts
@@ -1,10 +1,11 @@
+import { invariant, InvariantError } from '../globals';
+
import {
DocumentNode,
FragmentDefinitionNode,
InlineFragmentNode,
SelectionNode
} from 'graphql';
-import { invariant, InvariantError } from 'ts-invariant';
/**
* Returns a query document which adds a single query operation that only
diff --git a/src/utilities/graphql/getFromAST.ts b/src/utilities/graphql/getFromAST.ts
index 3cbc2d78abe..d87c73c0bde 100644
--- a/src/utilities/graphql/getFromAST.ts
+++ b/src/utilities/graphql/getFromAST.ts
@@ -1,3 +1,5 @@
+import { invariant, InvariantError } from '../globals';
+
import {
DocumentNode,
OperationDefinitionNode,
@@ -5,8 +7,6 @@ import {
ValueNode,
} from 'graphql';
-import { invariant, InvariantError } from 'ts-invariant';
-
import { valueToObjectRepresentation } from './storeUtils';
// Checks the document for errors and throws an exception if there is an error.
diff --git a/src/utilities/graphql/storeUtils.ts b/src/utilities/graphql/storeUtils.ts
index 8a7f4f45577..42f66fe9d6a 100644
--- a/src/utilities/graphql/storeUtils.ts
+++ b/src/utilities/graphql/storeUtils.ts
@@ -1,3 +1,5 @@
+import { InvariantError } from '../globals';
+
import {
DirectiveNode,
FieldNode,
@@ -18,7 +20,6 @@ import {
DocumentNode,
} from 'graphql';
-import { InvariantError } from 'ts-invariant';
import { isNonNullObject } from '../common/objects';
import { FragmentMap, getFragmentFromSelection } from './fragments';
diff --git a/src/utilities/graphql/transform.ts b/src/utilities/graphql/transform.ts
index aa4649be686..2a5128d0524 100644
--- a/src/utilities/graphql/transform.ts
+++ b/src/utilities/graphql/transform.ts
@@ -1,3 +1,5 @@
+import { invariant } from '../globals';
+
import {
DocumentNode,
SelectionNode,
@@ -12,7 +14,6 @@ import {
VariableNode,
visit,
} from 'graphql';
-import { invariant } from 'ts-invariant';
import {
checkDocument,
diff --git a/src/utilities/index.ts b/src/utilities/index.ts
index 7b5f3e3c61c..e03bc2862a4 100644
--- a/src/utilities/index.ts
+++ b/src/utilities/index.ts
@@ -1,6 +1,4 @@
-import { DEV, checkDEV } from "./globals";
-export { DEV, checkDEV }
-checkDEV();
+export { DEV, maybe } from './globals';
export {
DirectiveInfo,
@@ -83,7 +81,6 @@ export {
export * from './common/mergeDeep';
export * from './common/cloneDeep';
export * from './common/maybeDeepFreeze';
-export * from './common/maybe';
export * from './observables/iteration';
export * from './observables/asyncMap';
export * from './observables/Concast';
diff --git a/src/utilities/testing/mocking/mockLink.ts b/src/utilities/testing/mocking/mockLink.ts
index 22d3b687886..765fe28d319 100644
--- a/src/utilities/testing/mocking/mockLink.ts
+++ b/src/utilities/testing/mocking/mockLink.ts
@@ -1,6 +1,7 @@
+import { invariant } from '../../globals';
+
import { print } from 'graphql';
import { equal } from '@wry/equality';
-import { invariant } from 'ts-invariant';
import {
ApolloLink,