22
33const assert = require ( 'node:assert/strict' )
44const Module = require ( 'node:module' )
5+ const path = require ( 'node:path' )
56const { inspect } = require ( 'node:util' )
67
78const { describe, it, before, after } = require ( 'mocha' )
@@ -16,9 +17,14 @@ const sinon = require('sinon')
1617const loadableModule = /** @type {LoadableModule } */ ( Module )
1718
1819// The transforms module reads `globalThis[Symbol.for('dd-trace')].graphql_*`
19- // at require time, so populate them before requiring the tools.
20- const visitor = require ( 'graphql/language/visitor' )
21- const printer = require ( 'graphql/language/printer' )
20+ // at require time, so populate them before requiring the tools. Requiring by
21+ // absolute path (rather than the `graphql/language/visitor` subpath) bypasses
22+ // graphql's package.json `exports` map, so this always gets the mutable CJS
23+ // module instead of the read-only ES module namespace object that the
24+ // `module-sync` export condition resolves to on Node >=22.
25+ const graphqlRoot = path . dirname ( require . resolve ( 'graphql' ) )
26+ const visitor = require ( path . join ( graphqlRoot , 'language/visitor.js' ) )
27+ const printer = require ( path . join ( graphqlRoot , 'language/printer.js' ) )
2228const ddGlobal = globalThis [ Symbol . for ( 'dd-trace' ) ]
2329ddGlobal . graphql_visitor = visitor
2430ddGlobal . graphql_printer = printer
0 commit comments