diff --git a/jest.config.js b/jest.config.js index 714750d..75f626a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,5 +10,6 @@ module.exports = { "js", "ts", "node" - ] + ], + "testEnvironment": "node" } diff --git a/src/index.ts b/src/index.ts index 3b595f6..edcc72d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,11 @@ import { importSchema } from 'graphql-import' export default function(source) { const callback = this.async(); + const isFileRegex = /\.graphql$/i this.cacheable() - callback(null, `module.exports = \`${importSchema(source).replace(/`/g, '\\`')}\``) + const sdl = importSchema(isFileRegex.test(this.resource) ? this.resource : source) + + callback(null, `module.exports = \`${sdl.replace(/`/g, '\\`')}\``) } diff --git a/test/fixtures/complex.graphql b/test/fixtures/complex.graphql index d85677a..75403f2 100644 --- a/test/fixtures/complex.graphql +++ b/test/fixtures/complex.graphql @@ -1,6 +1,6 @@ -# import { A } from 'test/fixtures/a.graphql' -# import { B } from 'test/fixtures/b.graphql' -# import { C D } from 'test/fixtures/cd.graphql' +# import { A } from './a.graphql' +# import { B } from './b.graphql' +# import { C D } from './cd.graphql' type Complex { id: ID!