Skip to content

Commit

Permalink
Continue fixing bug with multiple imports in a schema file (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycuellar authored and detrohutt committed Jun 29, 2018
1 parent 485da2e commit 4680270
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugin/requireGql.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export const requireGql = (filepath, { resolve = defaultResolve, nowrap = true }
if (imports.length === 0) return source

// Resolve all #import statements (types, etc) recursively and concat them to the main source.
return imports
.reduce((acc, fp) => [...acc, ...customImport.getSources(fp, resolve, [source])], [])
.map(stripImportStatements)
.join('')
return (
imports
.reduce((acc, fp) => [...acc, ...customImport.getSources(fp, resolve, [])], [])
.map(stripImportStatements)
.join('') + stripImportStatements(source)
)
}

const doc = processDoc(createDoc(source, filepath, resolve))
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/requireGql.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type LevelOne {
levelTwo: LevelTwo
levelTwoBis: LevelTwoBis
}
type LevelOneBis {
levelTwo: LevelTwo
levelTwoBis: LevelTwoBis
}
type Query {
levelOne: LevelOne
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "./levelOne.graphql"
#import "./levelOneBis.graphql"

type Query {
levelOne: LevelOne
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/requireGql/customImport/levelOneBis.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type LevelOneBis {
levelTwo: LevelTwo
levelTwoBis: LevelTwoBis
}

0 comments on commit 4680270

Please sign in to comment.