Skip to content

Commit

Permalink
Revert "experiment: remove graphql package esm fix"
Browse files Browse the repository at this point in the history
This reverts commit 930783b.
  • Loading branch information
phryneas committed Jun 20, 2023
1 parent 930783b commit c5515fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utilities/globals/fix-graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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 { 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 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 { Source } from 'graphql';

export function removeTemporaryGlobals() {
// Using Source here here just to make sure it won't be tree-shaken away.
return typeof Source === "function" ? remove() : remove();
}
8 changes: 8 additions & 0 deletions src/utilities/globals/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { invariant, newInvariantError, InvariantError } from "./invariantWrappers";

// 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 "./fix-graphql";

// 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, newInvariantError, InvariantError }
Expand Down

0 comments on commit c5515fe

Please sign in to comment.