11import assert from 'node:assert' ;
22
3- import { GraphQLObjectType as ESMGraphQLObjectType } from 'graphql' ;
3+ import {
4+ GraphQLObjectType as ESMGraphQLObjectType ,
5+ GraphQLString as ESMGraphQLString ,
6+ isCompositeType as ESMIsCompositeType ,
7+ } from 'graphql' ;
8+ import {
9+ GraphQLObjectType as ESMTypeGraphQLObjectType ,
10+ GraphQLString as ESMTypeGraphQLString ,
11+ isCompositeType as ESMTypeIsCompositeType ,
12+ } from 'graphql/type' ;
413
5- import { CJSGraphQLObjectType , cjsPath } from './cjs-importer.cjs' ;
14+ import {
15+ CJSGraphQLObjectType ,
16+ CJSGraphQLString ,
17+ CJSIsCompositeType ,
18+ cjsPath ,
19+ CJSTypeGraphQLObjectType ,
20+ CJSTypeGraphQLString ,
21+ CJSTypeIsCompositeType ,
22+ cjsTypePath ,
23+ } from './cjs-importer.cjs' ;
624
725const moduleSync = process . env . MODULE_SYNC === 'true' ;
826const expectedExtension = moduleSync ? '.mjs' : '.js' ;
9- assert . ok (
10- cjsPath . endsWith ( expectedExtension ) ,
11- `require('graphql') should resolve to a file with extension "${ expectedExtension } ", but got "${ cjsPath } ".` ,
12- ) ;
27+ const resolvedPaths = [
28+ [ "require('graphql')" , cjsPath ] ,
29+ [ "require('graphql/type')" , cjsTypePath ] ,
30+ ] ;
31+
32+ for ( const [ specifier , resolvedPath ] of resolvedPaths ) {
33+ assert . ok (
34+ resolvedPath . endsWith ( expectedExtension ) ,
35+ `${ specifier } should resolve to a file with extension "${ expectedExtension } ", but got "${ resolvedPath } ".` ,
36+ ) ;
37+ }
1338
1439const isSameModule = ESMGraphQLObjectType === CJSGraphQLObjectType ;
1540assert . strictEqual (
@@ -18,4 +43,88 @@ assert.strictEqual(
1843 'ESM and CJS imports should be the same module instances.' ,
1944) ;
2045
21- console . log ( 'Module identity and path checks passed.' ) ;
46+ assert . strictEqual (
47+ ESMGraphQLObjectType ,
48+ ESMTypeGraphQLObjectType ,
49+ 'Root and graphql/type ESM imports should use the same GraphQLObjectType instance.' ,
50+ ) ;
51+ assert . strictEqual (
52+ CJSGraphQLObjectType ,
53+ CJSTypeGraphQLObjectType ,
54+ 'Root and graphql/type CJS imports should use the same GraphQLObjectType instance.' ,
55+ ) ;
56+ assert . strictEqual (
57+ ESMIsCompositeType ,
58+ ESMTypeIsCompositeType ,
59+ 'Root and graphql/type ESM imports should use the same isCompositeType predicate.' ,
60+ ) ;
61+ assert . strictEqual (
62+ CJSIsCompositeType ,
63+ CJSTypeIsCompositeType ,
64+ 'Root and graphql/type CJS imports should use the same isCompositeType predicate.' ,
65+ ) ;
66+ assert . strictEqual (
67+ ESMIsCompositeType ,
68+ CJSIsCompositeType ,
69+ 'ESM and CJS imports should use the same isCompositeType predicate.' ,
70+ ) ;
71+ assert . strictEqual (
72+ ESMGraphQLString ,
73+ ESMTypeGraphQLString ,
74+ 'Root and graphql/type ESM imports should use the same GraphQLString instance.' ,
75+ ) ;
76+ assert . strictEqual (
77+ CJSGraphQLString ,
78+ CJSTypeGraphQLString ,
79+ 'Root and graphql/type CJS imports should use the same GraphQLString instance.' ,
80+ ) ;
81+
82+ const objectTypes = [
83+ [
84+ 'ESM root GraphQLObjectType' ,
85+ new ESMGraphQLObjectType ( {
86+ name : 'ESMRootObjectType' ,
87+ fields : { field : { type : ESMGraphQLString } } ,
88+ } ) ,
89+ ] ,
90+ [
91+ 'ESM graphql/type GraphQLObjectType' ,
92+ new ESMTypeGraphQLObjectType ( {
93+ name : 'ESMTypeObjectType' ,
94+ fields : { field : { type : ESMTypeGraphQLString } } ,
95+ } ) ,
96+ ] ,
97+ [
98+ 'CJS root GraphQLObjectType' ,
99+ new CJSGraphQLObjectType ( {
100+ name : 'CJSRootObjectType' ,
101+ fields : { field : { type : CJSGraphQLString } } ,
102+ } ) ,
103+ ] ,
104+ [
105+ 'CJS graphql/type GraphQLObjectType' ,
106+ new CJSTypeGraphQLObjectType ( {
107+ name : 'CJSTypeObjectType' ,
108+ fields : { field : { type : CJSTypeGraphQLString } } ,
109+ } ) ,
110+ ] ,
111+ ] ;
112+
113+ const predicates = [
114+ [ 'ESM root isCompositeType' , ESMIsCompositeType ] ,
115+ [ 'ESM graphql/type isCompositeType' , ESMTypeIsCompositeType ] ,
116+ [ 'CJS root isCompositeType' , CJSIsCompositeType ] ,
117+ [ 'CJS graphql/type isCompositeType' , CJSTypeIsCompositeType ] ,
118+ ] ;
119+
120+ for ( const [ objectTypeLabel , objectType ] of objectTypes ) {
121+ for ( const [ predicateLabel , isCompositeType ] of predicates ) {
122+ assert . strictEqual (
123+ isCompositeType ( objectType ) ,
124+ true ,
125+ `${ predicateLabel } should return true for ${ objectTypeLabel } .` ,
126+ ) ;
127+ }
128+ }
129+
130+ console . log ( 'Module identity, subpath identity, and path checks passed.' ) ;
0 commit comments