@@ -78,67 +78,69 @@ export function resolveDocumentImports<T>(
7878 const { baseOutputDir, documents } = presetOptions ;
7979 const { generateFilePath, schemaTypesSource, baseDir, typesImport } = importResolverOptions ;
8080
81- return documents . map ( documentFile => {
82- try {
83- const meta : {
84- operations : OperationDefinitionNode [ ] ;
85- fragments : FragmentDefinitionNode [ ] ;
86- } = {
87- operations : [ ] ,
88- fragments : [ ] ,
89- } ;
90- for ( const definition of documentFile . document . definitions ) {
91- if ( definition . kind === Kind . OPERATION_DEFINITION ) {
92- meta . operations . push ( definition ) ;
93- } else if ( definition . kind === Kind . FRAGMENT_DEFINITION ) {
94- meta . fragments . push ( definition ) ;
81+ return documents
82+ . filter ( documentFile => documentFile . type !== 'external' )
83+ . map ( documentFile => {
84+ try {
85+ const meta : {
86+ operations : OperationDefinitionNode [ ] ;
87+ fragments : FragmentDefinitionNode [ ] ;
88+ } = {
89+ operations : [ ] ,
90+ fragments : [ ] ,
91+ } ;
92+ for ( const definition of documentFile . document . definitions ) {
93+ if ( definition . kind === Kind . OPERATION_DEFINITION ) {
94+ meta . operations . push ( definition ) ;
95+ } else if ( definition . kind === Kind . FRAGMENT_DEFINITION ) {
96+ meta . fragments . push ( definition ) ;
97+ }
9598 }
96- }
97- const generatedFilePath = generateFilePath ( { location : documentFile . location , meta } ) ;
99+ const generatedFilePath = generateFilePath ( { location : documentFile . location , meta } ) ;
98100
99- const importStatements : string [ ] = [ ] ;
100- const { externalFragments, fragmentImports } = resolveFragments (
101- generatedFilePath ,
102- documentFile . document ,
103- ) ;
101+ const importStatements : string [ ] = [ ] ;
102+ const { externalFragments, fragmentImports } = resolveFragments (
103+ generatedFilePath ,
104+ documentFile . document ,
105+ ) ;
104106
105- const externalFragmentsInjectedDocument = {
106- ...documentFile . document ,
107- definitions : [
108- ...documentFile . document . definitions ,
109- ...externalFragments . map ( fragment => fragment . node ) ,
110- ] ,
111- } ;
107+ const externalFragmentsInjectedDocument = {
108+ ...documentFile . document ,
109+ definitions : [
110+ ...documentFile . document . definitions ,
111+ ...externalFragments . map ( fragment => fragment . node ) ,
112+ ] ,
113+ } ;
112114
113- if (
114- isUsingTypes ( externalFragmentsInjectedDocument , [ ] , schemaObject ) &&
115- schemaTypesSource . namespace
116- ) {
117- const schemaTypesImportStatement = generateImportStatement ( {
118- baseDir,
119- emitLegacyCommonJSImports : presetOptions . config . emitLegacyCommonJSImports ,
120- importExtension : presetOptions . config . importExtension ,
121- importSource : resolveImportSource ( schemaTypesSource ) ,
122- baseOutputDir,
123- outputPath : generatedFilePath ,
124- typesImport,
125- } ) ;
126- importStatements . unshift ( schemaTypesImportStatement ) ;
127- }
115+ if (
116+ isUsingTypes ( externalFragmentsInjectedDocument , [ ] , schemaObject ) &&
117+ schemaTypesSource . namespace
118+ ) {
119+ const schemaTypesImportStatement = generateImportStatement ( {
120+ baseDir,
121+ emitLegacyCommonJSImports : presetOptions . config . emitLegacyCommonJSImports ,
122+ importExtension : presetOptions . config . importExtension ,
123+ importSource : resolveImportSource ( schemaTypesSource ) ,
124+ baseOutputDir,
125+ outputPath : generatedFilePath ,
126+ typesImport,
127+ } ) ;
128+ importStatements . unshift ( schemaTypesImportStatement ) ;
129+ }
128130
129- return {
130- filename : generatedFilePath ,
131- documents : [ documentFile ] ,
132- importStatements,
133- fragmentImports,
134- externalFragments,
135- } ;
136- } catch ( e ) {
137- throw new Error (
138- `Unable to validate GraphQL document! \n
131+ return {
132+ filename : generatedFilePath ,
133+ documents : [ documentFile ] ,
134+ importStatements,
135+ fragmentImports,
136+ externalFragments,
137+ } ;
138+ } catch ( e ) {
139+ throw new Error (
140+ `Unable to validate GraphQL document! \n
139141 File ${ documentFile . location } caused error:
140142 ${ e . message || e . toString ( ) } ` ,
141- ) ;
142- }
143- } ) ;
143+ ) ;
144+ }
145+ } ) ;
144146}
0 commit comments