Skip to content

Commit 61a39f5

Browse files
authoredApr 26, 2018
fix: file path import issues
2 parents 80f87a9 + ae31425 commit 61a39f5

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
 

‎fixtures/global/a.graphql

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# import * from "shared"
2+
3+
type A {
4+
first: String
5+
second: Shared
6+
}

‎src/index.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,25 @@ input PostFilter {
572572
t.is(actualSDL, expectedSDL)
573573
})
574574

575+
test('global schema modules', t => {
576+
const shared = `
577+
type Shared {
578+
first: String
579+
}
580+
`
581+
const expectedSDL = `\
582+
type A {
583+
first: String
584+
second: Shared
585+
}
586+
587+
type Shared {
588+
first: String
589+
}
590+
`
591+
t.is(importSchema('fixtures/global/a.graphql', { shared }), expectedSDL)
592+
})
593+
575594
test('missing type on type', t => {
576595
const err = t.throws(() => importSchema('fixtures/type-not-found/a.graphql'), Error)
577596
t.is(err.message, `Field test: Couldn't find type Post in any of the schemas.`)

‎src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ function collectDefinitions(
197197
// Process each file (recursively)
198198
rawModules.forEach(m => {
199199
// If it was not yet processed (in case of circular dependencies)
200-
const moduleFilePath = isFile(filePath) ? path.resolve(path.join(dirname, m.from)) : m.from
200+
const moduleFilePath = isFile(filePath) && isFile(m.from)
201+
? path.resolve(path.join(dirname, m.from))
202+
: m.from
201203
if (!processedFiles.has(moduleFilePath)) {
202204
collectDefinitions(
203205
m.imports,

0 commit comments

Comments
 (0)
Please sign in to comment.