File tree 4 files changed +31
-1
lines changed
fixtures/import-duplicate
4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
1
+ type Query {
2
+ first : String
3
+ second : Float
4
+ third : String
5
+ unused : String
6
+ }
Original file line number Diff line number Diff line change
1
+ # import Query.first, Query.second from "a.graphql"
2
+ # import Query.third from "a.graphql"
Original file line number Diff line number Diff line change @@ -76,6 +76,17 @@ type Query {
76
76
t . is ( importSchema ( 'fixtures/imports-only/all.graphql' ) , expectedSDL )
77
77
} )
78
78
79
+ test ( 'importSchema: import duplicate' , t => {
80
+ const expectedSDL = `\
81
+ type Query {
82
+ first: String
83
+ second: Float
84
+ third: String
85
+ }
86
+ `
87
+ t . is ( importSchema ( 'fixtures/import-duplicate/all.graphql' ) , expectedSDL )
88
+ } )
89
+
79
90
test ( 'importSchema: field types' , t => {
80
91
const expectedSDL = `\
81
92
type A {
Original file line number Diff line number Diff line change @@ -193,9 +193,20 @@ function collectDefinitions(
193
193
194
194
// Read imports from current file
195
195
const rawModules = parseSDL ( sdl )
196
+ const mergedModules : RawModule [ ] = [ ]
196
197
197
- // Process each file (recursively)
198
+ // Merge imports from the same path
198
199
rawModules . forEach ( m => {
200
+ const mergedModule = mergedModules . find ( mm => mm . from === m . from )
201
+ if ( mergedModule ) {
202
+ mergedModule . imports = mergedModule . imports . concat ( m . imports )
203
+ } else {
204
+ mergedModules . push ( m )
205
+ }
206
+ } )
207
+
208
+ // Process each file (recursively)
209
+ mergedModules . forEach ( m => {
199
210
// If it was not yet processed (in case of circular dependencies)
200
211
const moduleFilePath = isFile ( filePath ) && isFile ( m . from )
201
212
? path . resolve ( path . join ( dirname , m . from ) )
You can’t perform that action at this time.
0 commit comments