diff --git a/integrationTests/conditions/check.mjs b/integrationTests/conditions/check.mjs index c5086d3a82..d9719bc13f 100644 --- a/integrationTests/conditions/check.mjs +++ b/integrationTests/conditions/check.mjs @@ -1,15 +1,40 @@ import assert from 'node:assert'; -import { GraphQLObjectType as ESMGraphQLObjectType } from 'graphql'; +import { + GraphQLObjectType as ESMGraphQLObjectType, + GraphQLString as ESMGraphQLString, + isCompositeType as ESMIsCompositeType, +} from 'graphql'; +import { + GraphQLObjectType as ESMTypeGraphQLObjectType, + GraphQLString as ESMTypeGraphQLString, + isCompositeType as ESMTypeIsCompositeType, +} from 'graphql/type'; -import { CJSGraphQLObjectType, cjsPath } from './cjs-importer.cjs'; +import { + CJSGraphQLObjectType, + CJSGraphQLString, + CJSIsCompositeType, + cjsPath, + CJSTypeGraphQLObjectType, + CJSTypeGraphQLString, + CJSTypeIsCompositeType, + cjsTypePath, +} from './cjs-importer.cjs'; const moduleSync = process.env.MODULE_SYNC === 'true'; const expectedExtension = moduleSync ? '.mjs' : '.js'; -assert.ok( - cjsPath.endsWith(expectedExtension), - `require('graphql') should resolve to a file with extension "${expectedExtension}", but got "${cjsPath}".`, -); +const resolvedPaths = [ + ["require('graphql')", cjsPath], + ["require('graphql/type')", cjsTypePath], +]; + +for (const [specifier, resolvedPath] of resolvedPaths) { + assert.ok( + resolvedPath.endsWith(expectedExtension), + `${specifier} should resolve to a file with extension "${expectedExtension}", but got "${resolvedPath}".`, + ); +} const isSameModule = ESMGraphQLObjectType === CJSGraphQLObjectType; assert.strictEqual( @@ -18,4 +43,88 @@ assert.strictEqual( 'ESM and CJS imports should be the same module instances.', ); -console.log('Module identity and path checks passed.'); +assert.strictEqual( + ESMGraphQLObjectType, + ESMTypeGraphQLObjectType, + 'Root and graphql/type ESM imports should use the same GraphQLObjectType instance.', +); +assert.strictEqual( + CJSGraphQLObjectType, + CJSTypeGraphQLObjectType, + 'Root and graphql/type CJS imports should use the same GraphQLObjectType instance.', +); +assert.strictEqual( + ESMIsCompositeType, + ESMTypeIsCompositeType, + 'Root and graphql/type ESM imports should use the same isCompositeType predicate.', +); +assert.strictEqual( + CJSIsCompositeType, + CJSTypeIsCompositeType, + 'Root and graphql/type CJS imports should use the same isCompositeType predicate.', +); +assert.strictEqual( + ESMIsCompositeType, + CJSIsCompositeType, + 'ESM and CJS imports should use the same isCompositeType predicate.', +); +assert.strictEqual( + ESMGraphQLString, + ESMTypeGraphQLString, + 'Root and graphql/type ESM imports should use the same GraphQLString instance.', +); +assert.strictEqual( + CJSGraphQLString, + CJSTypeGraphQLString, + 'Root and graphql/type CJS imports should use the same GraphQLString instance.', +); + +const objectTypes = [ + [ + 'ESM root GraphQLObjectType', + new ESMGraphQLObjectType({ + name: 'ESMRootObjectType', + fields: { field: { type: ESMGraphQLString } }, + }), + ], + [ + 'ESM graphql/type GraphQLObjectType', + new ESMTypeGraphQLObjectType({ + name: 'ESMTypeObjectType', + fields: { field: { type: ESMTypeGraphQLString } }, + }), + ], + [ + 'CJS root GraphQLObjectType', + new CJSGraphQLObjectType({ + name: 'CJSRootObjectType', + fields: { field: { type: CJSGraphQLString } }, + }), + ], + [ + 'CJS graphql/type GraphQLObjectType', + new CJSTypeGraphQLObjectType({ + name: 'CJSTypeObjectType', + fields: { field: { type: CJSTypeGraphQLString } }, + }), + ], +]; + +const predicates = [ + ['ESM root isCompositeType', ESMIsCompositeType], + ['ESM graphql/type isCompositeType', ESMTypeIsCompositeType], + ['CJS root isCompositeType', CJSIsCompositeType], + ['CJS graphql/type isCompositeType', CJSTypeIsCompositeType], +]; + +for (const [objectTypeLabel, objectType] of objectTypes) { + for (const [predicateLabel, isCompositeType] of predicates) { + assert.strictEqual( + isCompositeType(objectType), + true, + `${predicateLabel} should return true for ${objectTypeLabel}.`, + ); + } +} + +console.log('Module identity, subpath identity, and path checks passed.'); diff --git a/integrationTests/conditions/cjs-importer.cjs b/integrationTests/conditions/cjs-importer.cjs index fbb7520c12..7b9db0bf8d 100644 --- a/integrationTests/conditions/cjs-importer.cjs +++ b/integrationTests/conditions/cjs-importer.cjs @@ -1,11 +1,27 @@ 'use strict'; -const { GraphQLObjectType } = require('graphql'); +const { + GraphQLObjectType, + GraphQLString, + isCompositeType, +} = require('graphql'); +const { + GraphQLObjectType: TypeGraphQLObjectType, + GraphQLString: TypeGraphQLString, + isCompositeType: typeIsCompositeType, +} = require('graphql/type'); const cjsPath = require.resolve('graphql'); +const cjsTypePath = require.resolve('graphql/type'); // eslint-disable-next-line import/no-commonjs module.exports = { CJSGraphQLObjectType: GraphQLObjectType, + CJSGraphQLString: GraphQLString, + CJSIsCompositeType: isCompositeType, + CJSTypeGraphQLObjectType: TypeGraphQLObjectType, + CJSTypeGraphQLString: TypeGraphQLString, + CJSTypeIsCompositeType: typeIsCompositeType, cjsPath, + cjsTypePath, };