Skip to content

Commit db0696d

Browse files
committed
Set up vitest for graphql version 16 and 15 as well
1 parent 9c2b76e commit db0696d

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

vitest.config.mts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { createRequire } from 'module';
22
import { dirname, resolve } from 'path';
3+
import { versionInfo } from 'graphql';
34
import { defineConfig } from 'vitest/config';
45

5-
// Use an absolute path to graphql/index.mjs so ALL imports (Vite-processed
6-
// and Node.js-native) resolve to the same ESM module in Node.js's module cache,
7-
// preventing graphql@17's devInstanceOf from detecting false cross-realm usage.
8-
const _require = createRequire(import.meta.url);
9-
// require.resolve('graphql') returns index.mjs in Node.js v24 (via module-sync condition)
10-
const graphqlIndexMjs = resolve(dirname(_require.resolve('graphql')), 'index.mjs');
11-
126
export const sharedConfig = defineConfig({
137
resolve: {
148
alias: {
15-
graphql: graphqlIndexMjs,
9+
graphql: (function resolveGraphQL() {
10+
if (versionInfo.major < 17) {
11+
return 'graphql/index.js';
12+
}
13+
// Use an absolute path to graphql/index.mjs so ALL imports (Vite-processed
14+
// and Node.js-native) resolve to the same ESM module in Node.js's module cache,
15+
// preventing graphql@17's devInstanceOf from detecting false cross-realm usage.
16+
const _require = createRequire(import.meta.url);
17+
// require.resolve('graphql') returns index.mjs in Node.js v24 (via module-sync condition)
18+
const graphqlIndexMjs = resolve(dirname(_require.resolve('graphql')), 'index.mjs');
19+
return graphqlIndexMjs;
20+
})(),
1621
},
1722
tsconfigPaths: true,
1823
},

0 commit comments

Comments
 (0)