Skip to content

switch to esm-only with development condition enabling dev-instanceOf-check #4437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node_version_to_setup: [16, 18, 19]
node_version_to_setup: [20, 22, 23]
permissions:
contents: read # for actions/checkout
steps:
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20
v22
7 changes: 5 additions & 2 deletions cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ overrides:
- URQL
- tada
- Graphile
- precompiled
- debuggable
- precompileds
- Rollup
- Turbopack

validateDirectives: true
ignoreRegExpList:
Expand All @@ -67,6 +68,8 @@ words:
# TODO: contribute upstream
- deno
- hashbang
- Rspack
- Rsbuild

# Website tech
- Nextra
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ export default tsConfig(
'n/no-missing-import': [
'error',
{
allowModules: ['graphql', 'graphql-esm'],
allowModules: ['graphql'],
},
],
'n/no-missing-require': [
Expand Down
44 changes: 43 additions & 1 deletion integrationTests/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
# TBD
# Integration Tests

This directory contains integration tests for GraphQL.js across different environments and bundlers, testing basic GraphQL.JS functionality, as well as development mode and production mode behavior.

Tests are run via the main integration test suite in `resources/integration-test.ts`.

## Test Structure

### Basic GraphQL.JS Functionality Tests

Each subdirectory represents a different environment/bundler:

- `node` - tests for supported Node.js versions
- `ts` - tests for supported Typescript versions
- `webpack` - tests for Webpack

### Verifying Development Mode Tests

Each subdirectory represents a different environment/bundler demonstrating enabling development mode via conditional exports or by explicitly importing `graphql/dev`:

- `dev-bun/`: via `bun --conditions=development test.js`
- `dev-deno-implicit`: via `deno run --unstable-node-conditions=development test.js`
- `dev-deno-explicit`: via `import 'graphql/dev'`
- `dev-node-implicit`: via `node --conditions=development test.js`
- `dev-node-explicit`: via `import 'graphql/dev'`
- `dev-webpack`: via `{resolve: { conditionNames: ['development'] } }`
- `dev-rspack`: via `{resolve: { conditionNames: ['development'] } }`
- `dev-esbuild`: via `esbuild --conditions=development test.js`
- `dev-rollup`: via `@rollup/plugin-node-resolve` with `conditions: ['development']`
- `dev-swc`: via `import 'graphql/dev'`

### Verifying Production Mode Tests

Each subdirectory represents a different environment/bundler demonstrating production mode when development mode is not enabled:

- `prod-bun/`: via `bun test.js`
- `prod-deno`: via `deno run test.js`
- `prod-node`: via `node test.js`
- `prod-webpack`: via default Webpack configuration
- `prod-rspack`: via default Rspack configuration
- `prod-esbuild`: via `esbuild test.js`
- `prod-rollup`: via default Rollup configuration
- `prod-swc`: via default SWC configuration
10 changes: 10 additions & 0 deletions integrationTests/dev-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js development condition should work with Bun",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app oven/bun:latest bun --conditions=development test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-bun/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
10 changes: 10 additions & 0 deletions integrationTests/dev-deno-explicit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js explicit development import should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app denoland/deno:latest deno run test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
20 changes: 20 additions & 0 deletions integrationTests/dev-deno-explicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// eslint-disable-next-line import/no-unassigned-import, simple-import-sort/imports
import 'graphql/dev';
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
10 changes: 10 additions & 0 deletions integrationTests/dev-deno-implicit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js development condition should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD:/usr/src/app\" -w /usr/src/app denoland/deno:latest deno run --unstable-node-conditions=development test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-deno-implicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
13 changes: 13 additions & 0 deletions integrationTests/dev-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "graphql-js development condition should work with esbuild",
"private": true,
"type": "module",
"scripts": {
"build": "esbuild src/index.js --bundle --outfile=dist/bundle.js --format=esm --conditions=development,module",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"esbuild": "^0.25.0"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-esbuild/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
3 changes: 3 additions & 0 deletions integrationTests/dev-node-explicit/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable import/no-unassigned-import */
import 'graphql/dev';
import './test.js';
11 changes: 11 additions & 0 deletions integrationTests/dev-node-explicit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "explicit graphql-js development mode should work with node",
"private": true,
"type": "module",
"scripts": {
"test": "node bootstrap.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-node-explicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
11 changes: 11 additions & 0 deletions integrationTests/dev-node-implicit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "graphql-js development condition should work with node",
"private": true,
"type": "module",
"scripts": {
"test": "node --conditions=development test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-node-implicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
14 changes: 14 additions & 0 deletions integrationTests/dev-rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"description": "graphql-js development condition should work with Rollup",
"private": true,
"type": "module",
"scripts": {
"build": "rollup -c",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"rollup": "^4.0.0",
"@rollup/plugin-node-resolve": "^15.0.0"
}
}
18 changes: 18 additions & 0 deletions integrationTests/dev-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line n/no-missing-import
import resolve from '@rollup/plugin-node-resolve';

const rollupConfig = {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'es',
},
plugins: [
resolve({
exportConditions: ['development'],
}),
],
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default rollupConfig;
18 changes: 18 additions & 0 deletions integrationTests/dev-rollup/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
12 changes: 12 additions & 0 deletions integrationTests/dev-rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"description": "graphql-js development condition should work with Rspack",
"private": true,
"scripts": {
"test": "rspack --mode=development && node dist/main.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"@rspack/core": "^1.0.0",
"@rspack/cli": "^1.0.0"
}
}
20 changes: 20 additions & 0 deletions integrationTests/dev-rspack/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fileURLToPath } from 'node:url';

const rspack = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: fileURLToPath(new URL('dist', import.meta.url)),
library: {
type: 'commonjs2',
},
},
mode: 'development',
target: 'node',
resolve: {
conditionNames: ['development', 'import', 'node'],
},
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default rspack;
18 changes: 18 additions & 0 deletions integrationTests/dev-rspack/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isObjectType } from 'graphql';

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit dev import mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
12 changes: 12 additions & 0 deletions integrationTests/dev-swc/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2020"
},
"module": {
"type": "es6"
}
}
Loading
Loading