Skip to content

Commit

Permalink
Safely require cleanDocument/toSimpleDocument in graphql-mini-trannsf…
Browse files Browse the repository at this point in the history
…orms

The "jest" and "jest-simple" transforms for graphql-mini-transforms use
__dirname in order to retrieve the absolute path to the relative file
"document.js" when loading the cleanDocument and toSimpleDocument
utilities.

As a result, when the path to these files changes, such as when the
package is updated under a manager like pnpm, the directory path will be
different but the cache key will not change, causing it to try and
use the Jest cached version of these files

Since both cleanDocument and toSimpleDocument are exported at the
top-level, we should just reference the `graphql-mini-transforms`
package directly in the require statement.
  • Loading branch information
ryanwilsonperkin committed Apr 16, 2024
1 parent 7c9af53 commit 6efb945
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-ghosts-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-mini-transforms': patch
---

Prevent bad cache entry for jest and jest-simple transforms referencing stale node_modules paths
4 changes: 1 addition & 3 deletions packages/graphql-mini-transforms/src/jest-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const transformer: Transformer = {

const utilityImports = `
var {print, parse} = require('graphql');
var {cleanDocument, toSimpleDocument} = require(${JSON.stringify(
`${__dirname}/document.js`,
)});
var {cleanDocument, toSimpleDocument} = require('graphql-mini-transforms');
`;

const importSource = imports
Expand Down
4 changes: 1 addition & 3 deletions packages/graphql-mini-transforms/src/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const transformer: Transformer = {

const utilityImports = `
var {print} = require('graphql');
var {cleanDocument} = require(${JSON.stringify(
`${__dirname}/document.js`,
)});
var {cleanDocument} = require('graphql-mini-transforms');
`;

const importSource = imports
Expand Down

0 comments on commit 6efb945

Please sign in to comment.