Skip to content

Commit 7ed7d05

Browse files
committed
use dev/prod conditions to set instanceOf check
1 parent ae18fca commit 7ed7d05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1033
-202
lines changed

cspell.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ overrides:
4040
- tada
4141
- Graphile
4242
- precompiled
43-
- debuggable
43+
- Rollup
44+
- Turbopack
4445

4546
validateDirectives: true
4647
ignoreRegExpList:

integrationTests/README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# TBD
1+
# Integration Tests
2+
3+
This directory contains integration tests for GraphQL.js across different environments and bundlers, testing both development mode and production mode functionality.
4+
5+
## Test Structure
6+
7+
Each subdirectory represents a different environment/bundler:
8+
9+
- `node/` - Node.js runtime tests
10+
- `deno/` - Deno runtime tests
11+
- `bun/` - Bun runtime tests
12+
- `webpack/` - Webpack bundler tests
13+
- `rollup/` - Rollup bundler tests
14+
- `esbuild/` - esbuild bundler tests
15+
- `vite/` - Vite bundler tests
16+
- `nextjs/` - Next.js framework tests
17+
- `create-react-app/` - Create React App tests
18+
- `swc/` - SWC bundler tests
19+
20+
## Development Mode Testing
21+
22+
Each test verifies:
23+
1. Development mode is properly enabled (explicit import or conditional exports)
24+
2. Production mode works without development overhead
25+
3. Multiple GraphQL.js module detection works in development
26+
4. Performance characteristics differ between modes
27+
28+
## Running Tests
29+
30+
Tests are run via the main integration test suite in `resources/integration-test.ts`.

integrationTests/dev-bun/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"description": "graphql-js development condition should work with Bun",
3+
"private": true,
4+
"scripts": {
5+
"test": "bun --conditions=development test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz"
9+
}
10+
}

integrationTests/dev-bun/test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Bun development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in Bun development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"description": "graphql-js development condition should work with Deno",
3+
"private": true,
4+
"scripts": {
5+
"test": "deno run --unstable-node-conditions=development test.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz"
9+
}
10+
}

integrationTests/dev-deno/test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Deno development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in Deno development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"description": "graphql-js development condition should work with esbuild",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "esbuild src/index.js --bundle --outfile=dist/bundle.js --format=esm --conditions=development,module",
7+
"test": "npm run build && node dist/bundle.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz"
11+
},
12+
"devDependencies": {
13+
"esbuild": "^0.20.0"
14+
}
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in esbuild development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in esbuild development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint-disable import/no-unassigned-import */
2+
import 'graphql/dev';
3+
import './test.js';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"description": "explicit graphql-js development mode should work with node",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"test": "node bootstrap.js"
7+
},
8+
"dependencies": {
9+
"graphql": "file:../graphql.tgz"
10+
}
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
// If isObjectType did not throw, this line will be reached.
12+
throw new Error(
13+
'Expected isObjectType to throw an error in Node.js explicit development mode.',
14+
);
15+
} catch (error) {
16+
// Case 1: The error is the one we threw from the 'try' block.
17+
// This means isObjectType() itself did NOT throw an error.
18+
if (
19+
error.message ===
20+
'Expected isObjectType to throw an error in Node.js explicit development mode.'
21+
) {
22+
throw error; // Re-throw this error to indicate the test failure.
23+
}
24+
// Case 2: isObjectType() itself threw an error. Now check if it's the correct error.
25+
else if (!error.message.includes('from another module or realm')) {
26+
// If the message does NOT include the expected text, then it's the wrong error.
27+
throw new Error(
28+
`Expected error message to include 'from another module or realm', but got: "${error.message}"`,
29+
);
30+
}
31+
// If none of the above, it means isObjectType() threw an error, AND that error's message was correct.
32+
// So, the test passes by not throwing anything further from the catch block.
33+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"description": "graphql-js development condition should work with node",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"test": "node --conditions=development test.js"
7+
},
8+
"dependencies": {
9+
"graphql": "file:../graphql.tgz"
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Node.js implicit development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in Node.js implicit development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"description": "graphql-js development condition should work with Rollup",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "rollup -c",
7+
"test": "npm run build && node dist/bundle.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz"
11+
},
12+
"devDependencies": {
13+
"rollup": "^4.0.0",
14+
"@rollup/plugin-node-resolve": "^15.0.0"
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import resolve from '@rollup/plugin-node-resolve';
2+
3+
export default {
4+
input: 'src/index.js',
5+
output: {
6+
file: 'dist/bundle.js',
7+
format: 'es'
8+
},
9+
plugins: [
10+
resolve({
11+
exportConditions: ['development']
12+
})
13+
]
14+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in Rollup development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in Rollup development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}

integrationTests/dev-swc/.swcrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "ecmascript",
5+
"jsx": false
6+
},
7+
"target": "es2020"
8+
},
9+
"module": {
10+
"type": "es6"
11+
}
12+
}

integrationTests/dev-swc/bootstrap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// SWC doesn't support conditional exports, so we use explicit development mode
2+
import 'graphql/dev';
3+
import './dist/index.js';

integrationTests/dev-swc/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"description": "graphql-js development condition should work with SWC",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "swc src -d dist",
7+
"test": "npm run build && node bootstrap.js"
8+
},
9+
"dependencies": {
10+
"graphql": "file:../graphql.tgz"
11+
},
12+
"devDependencies": {
13+
"@swc/cli": "^0.1.0",
14+
"@swc/core": "^1.3.0"
15+
}
16+
}

integrationTests/dev-swc/src/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { isObjectType } from 'graphql';
2+
3+
class GraphQLObjectType {
4+
get [Symbol.toStringTag]() {
5+
return 'GraphQLObjectType';
6+
}
7+
}
8+
9+
try {
10+
isObjectType(new GraphQLObjectType());
11+
throw new Error(
12+
'Expected isObjectType to throw an error in SWC development mode.',
13+
);
14+
} catch (error) {
15+
if (
16+
error.message ===
17+
'Expected isObjectType to throw an error in SWC development mode.'
18+
) {
19+
throw error;
20+
}
21+
if (
22+
!(error.message.includes('multiple') || error.message.includes('GraphQL'))
23+
) {
24+
throw new Error(
25+
`Expected error message to include 'multiple' or 'GraphQL', but got: "${error.message}"`,
26+
);
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"description": "graphql-js development condition should work with Webpack",
3+
"private": true,
4+
"scripts": {
5+
"test": "webpack --mode=development && node dist/main.js"
6+
},
7+
"dependencies": {
8+
"graphql": "file:../graphql.tgz"
9+
},
10+
"devDependencies": {
11+
"webpack": "^5.0.0",
12+
"webpack-cli": "^5.0.0"
13+
}
14+
}

0 commit comments

Comments
 (0)