Skip to content

Commit bac9499

Browse files
committed
feat(loader): Use relative path inside SDL
Use the file path instead of file content to import schema. Set Jest's environment to node to avoid the error with jsdom's localStorage, see jestjs/jest#6766 and jsdom/jsdom#2304. BREAKING CHANGE: Use absolute path inside DSL won't work anymore, but now will be the same behavior of `graphql-import` dealing with paths. Fix #10
1 parent 586e4ee commit bac9499

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ module.exports = {
1010
"js",
1111
"ts",
1212
"node"
13-
]
13+
],
14+
"testEnvironment": "node"
1415
}

src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { importSchema } from 'graphql-import'
22

33
export default function(source) {
44
const callback = this.async();
5+
const isFileRegex = /\.graphql$/i
56

67
this.cacheable()
78

8-
callback(null, `module.exports = \`${importSchema(source).replace(/`/g, '\\`')}\``)
9+
const sdl = importSchema(isFileRegex.test(this.resource) ? this.resource : source)
10+
11+
callback(null, `module.exports = \`${sdl.replace(/`/g, '\\`')}\``)
912
}

test/fixtures/complex.graphql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# import { A } from 'test/fixtures/a.graphql'
2-
# import { B } from 'test/fixtures/b.graphql'
3-
# import { C D } from 'test/fixtures/cd.graphql'
1+
# import { A } from './a.graphql'
2+
# import { B } from './b.graphql'
3+
# import { C D } from './cd.graphql'
44

55
type Complex {
66
id: ID!

0 commit comments

Comments
 (0)