@@ -104,7 +104,7 @@ export async function processConfig(
104104 const importCodes = new Set ( [
105105 `import type { GetMeshOptions } from '@graphql-mesh/runtime';` ,
106106 `import type { YamlConfig } from '@graphql-mesh/types';` ,
107- `import { defaultImportFn } from '@graphql-mesh/utils';` ,
107+ `import { defaultImportFn, handleImport } from '@graphql-mesh/utils';` ,
108108 ] ) ;
109109 const codes = new Set ( [
110110 `export const rawServeConfig: YamlConfig.Config['serve'] = ${ JSON . stringify (
@@ -124,7 +124,7 @@ export async function processConfig(
124124 if ( config . require ) {
125125 await Promise . all ( config . require . map ( mod => importFn ( mod ) ) ) ;
126126 for ( const mod of config . require ) {
127- importCodes . add ( `import '${ mod } ';` ) ;
127+ codes . add ( `await import( '${ mod } ') ;` ) ;
128128 }
129129 }
130130
@@ -208,11 +208,10 @@ export async function processConfig(
208208 additionalPrefixes : additionalPackagePrefixes ,
209209 } ) . then ( ( { resolved : HandlerCtor , moduleName } ) => {
210210 if ( options . generateCode ) {
211- const handlerImportName = pascalCase ( handlerName + '_Handler' ) ;
211+ const handlerImportName = pascalCase ( handlerVariableName ) ;
212212 codes . add (
213- `const ${ handlerImportName } = await defaultImportFn(${ JSON . stringify ( moduleName ) } );` ,
214- ) ;
215- codes . add ( `const ${ handlerVariableName } = new ${ handlerImportName } ({
213+ `const ${ handlerImportName } = await import(${ JSON . stringify ( moduleName ) } ).then(handleImport);\n` +
214+ `const ${ handlerVariableName } = new ${ handlerImportName } ({
216215 name: ${ JSON . stringify ( source . name ) } ,
217216 config: ${ JSON . stringify ( handlerConfig ) } ,
218217 baseDir,
@@ -221,7 +220,8 @@ export async function processConfig(
221220 store: sourcesStore.child(${ JSON . stringify ( source . name ) } ),
222221 logger: logger.child(${ JSON . stringify ( source . name ) } ),
223222 importFn,
224- });` ) ;
223+ });` ,
224+ ) ;
225225 }
226226 return new HandlerCtor ( {
227227 name : source . name ,
@@ -248,19 +248,19 @@ export async function processConfig(
248248 } ) ;
249249
250250 if ( options . generateCode ) {
251- const transformImportName = pascalCase ( transformName + '_Transform' ) ;
251+ const transformImportName = pascalCase ( transformsVariableName ) ;
252252 codes . add (
253- `const ${ transformImportName } = await defaultImportFn(${ JSON . stringify ( moduleName ) } );` ,
254- ) ;
255- codes . add ( `${ transformsVariableName } [${ transformIndex } ] = new ${ transformImportName } ({
253+ `const ${ transformImportName } = await import(${ JSON . stringify ( moduleName ) } ).then(handleImport);\n` +
254+ `${ transformsVariableName } [${ transformIndex } ] = new ${ transformImportName } ({
256255 apiName: ${ JSON . stringify ( source . name ) } ,
257256 config: ${ JSON . stringify ( transformConfig ) } ,
258257 baseDir,
259258 cache,
260259 pubsub,
261260 importFn,
262261 logger,
263- });` ) ;
262+ });` ,
263+ ) ;
264264 }
265265
266266 return new TransformCtor ( {
@@ -304,18 +304,19 @@ export async function processConfig(
304304 } ) ;
305305
306306 if ( options . generateCode ) {
307- const transformImportName = pascalCase ( transformName + '_Transform' ) ;
308- importCodes . add ( `import ${ transformImportName } from ${ JSON . stringify ( moduleName ) } ;` ) ;
309-
310- codes . add ( `transforms[${ transformIndex } ] = new ( ${ transformImportName } as any) ({
307+ const transformImportName = pascalCase ( 'Root_Transform_' + transformIndex ) ;
308+ codes . add (
309+ `const ${ transformImportName } = await import( ${ JSON . stringify ( moduleName ) } ).then(handleImport);\n` +
310+ `transforms[${ transformIndex } ] = new ${ transformImportName } ({
311311 apiName: '',
312312 config: ${ JSON . stringify ( transformConfig ) } ,
313313 baseDir,
314314 cache,
315315 pubsub,
316316 importFn,
317317 logger,
318- })` ) ;
318+ })` ,
319+ ) ;
319320 }
320321 return new TransformLibrary ( {
321322 apiName : '' ,
@@ -337,7 +338,7 @@ export async function processConfig(
337338 if ( options . generateCode ) {
338339 const importProp = `[${ JSON . stringify ( importName ) } ]` ;
339340 codes . add (
340- `const ${ importName } = await defaultImportFn (${ JSON . stringify ( moduleName ) } ).then(m => m?.${ importProp } );` ,
341+ `const ${ importName } = await import (${ JSON . stringify ( moduleName ) } ).then(m => m?.${ importProp } );` ,
341342 ) ;
342343 codes . add (
343344 `additionalEnvelopPlugins[${ pluginIndex } ] = await ${ importName } (${ JSON . stringify (
@@ -367,7 +368,7 @@ export async function processConfig(
367368 if ( options . generateCode ) {
368369 const importName = camelCase ( 'use_' + pluginName ) ;
369370 codes . add (
370- `const ${ importName } = await defaultImportFn (${ JSON . stringify ( moduleName ) } );` ,
371+ `const ${ importName } = await import (${ JSON . stringify ( moduleName ) } ).then(handleImport );` ,
371372 ) ;
372373 codes . add ( `additionalEnvelopPlugins[${ pluginIndex } ] = await ${ importName } ({
373374 ...(${ JSON . stringify ( pluginConfig , null , 2 ) } ),
@@ -548,7 +549,9 @@ export async function processConfig(
548549
549550 const mergerLoggerPrefix = `${ mergerName } Merger` ;
550551 if ( options . generateCode ) {
551- codes . add ( `const Merger = await defaultImportFn(${ JSON . stringify ( mergerModuleName ) } );` ) ;
552+ codes . add (
553+ `const Merger = await import(${ JSON . stringify ( mergerModuleName ) } ).then(handleImport);` ,
554+ ) ;
552555 codes . add ( `const merger = new Merger({
553556 cache,
554557 pubsub,
@@ -566,9 +569,9 @@ export async function processConfig(
566569
567570 if ( config . additionalEnvelopPlugins ) {
568571 codes . add (
569- `const importedAdditionalEnvelopPlugins = await defaultImportFn (${ JSON . stringify (
572+ `const importedAdditionalEnvelopPlugins = await import (${ JSON . stringify (
570573 pathModule . join ( '..' , config . additionalEnvelopPlugins ) . split ( '\\' ) . join ( '/' ) ,
571- ) } );`,
574+ ) } ).then(handleImport) ;`,
572575 ) ;
573576 const importedAdditionalEnvelopPlugins = await importFn (
574577 pathModule . isAbsolute ( config . additionalEnvelopPlugins )
@@ -649,7 +652,7 @@ export async function processConfig(
649652 ${ [ ...documentHashMapCodes ] . join ( ',\n' ) }
650653 }` ) ;
651654 codes . add (
652- `const usePersistedOperations = await defaultImportFn ('@graphql-yoga/plugin-persisted-operations').then(m => m?.usePersistedOperations);` ,
655+ `const usePersistedOperations = await import ('@graphql-yoga/plugin-persisted-operations').then(m => m?.usePersistedOperations);` ,
653656 ) ;
654657 codes . add ( `additionalEnvelopPlugins.push(usePersistedOperations({
655658 getPersistedOperation(key) {
0 commit comments