Skip to content

Commit

Permalink
fix: file path import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
schickling committed Apr 26, 2018
2 parents 80f87a9 + ae31425 commit 61a39f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions fixtures/global/a.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# import * from "shared"

type A {
first: String
second: Shared
}
19 changes: 19 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,25 @@ input PostFilter {
t.is(actualSDL, expectedSDL)
})

test('global schema modules', t => {
const shared = `
type Shared {
first: String
}
`
const expectedSDL = `\
type A {
first: String
second: Shared
}
type Shared {
first: String
}
`
t.is(importSchema('fixtures/global/a.graphql', { shared }), expectedSDL)
})

test('missing type on type', t => {
const err = t.throws(() => importSchema('fixtures/type-not-found/a.graphql'), Error)
t.is(err.message, `Field test: Couldn't find type Post in any of the schemas.`)
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ function collectDefinitions(
// Process each file (recursively)
rawModules.forEach(m => {
// If it was not yet processed (in case of circular dependencies)
const moduleFilePath = isFile(filePath) ? path.resolve(path.join(dirname, m.from)) : m.from
const moduleFilePath = isFile(filePath) && isFile(m.from)
? path.resolve(path.join(dirname, m.from))
: m.from
if (!processedFiles.has(moduleFilePath)) {
collectDefinitions(
m.imports,
Expand Down

0 comments on commit 61a39f5

Please sign in to comment.