Skip to content

Commit

Permalink
feat(loader): Use relative path inside SDL
Browse files Browse the repository at this point in the history
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 prisma-labs#10
  • Loading branch information
leosuncin committed Jan 28, 2019
1 parent 586e4ee commit bac9499
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
"js",
"ts",
"node"
]
],
"testEnvironment": "node"
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\`')}\``)
}
6 changes: 3 additions & 3 deletions test/fixtures/complex.graphql
Original file line number Diff line number Diff line change
@@ -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!
Expand Down

0 comments on commit bac9499

Please sign in to comment.