Skip to content

Commit

Permalink
fix: ensure graphql key is a valid graphql key value
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchau committed Feb 13, 2018
1 parent 3739df7 commit 1e3740e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby/src/schema/__tests__/create-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe(`createKey`, () => {
it(`replaces invalid characters`, () => {
;[
[`/hello`, `_hello`],
[`~/path/to/some/module`, `_-path-to-some-module`],
[`/*`, `_-`],
[`/*.js`, `_--js`],
[`~/path/to/some/module`, `_xpathxtoxsomexmodule`],
[`/*`, `_x`],
[`/*.js`, `_xxjs`],
].forEach(([input, output]) => {
expect(createKey(input)).toBe(output)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/create-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = (key: string): string => {

// key is invalid; normalize with a leading underscore and dasherize rest
if (replaced.match(/^__/)) {
return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `-`))
return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `x`))
}

return replaced
Expand Down

0 comments on commit 1e3740e

Please sign in to comment.