relay-compiler: Does not account for backslashes that are part of escape sequences.
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
First off thanks for creating relay, its fabulous.
I'm having an issue related to graphql tagged template literals. I'm including explicit new line characters when forming my queries.
`hello/Hello.js`
```
import graphql from 'react-relay'
graphql`query HelloQuery {\n allLinks {\n id\n url\n }\n}`
```
`schema.graphql`
```
type Link {
description: String
id: ID!
url: String
}
type Query {
allLinks: [Link]!
}
```
Looking at the [graphql spec](https://github.com/facebook/graphql/blob/master/spec/Section%202%20--%20Language.md#line-terminators), the way I understand it is the newline characters shouldn't matter.
However, when using relay-compiler 1.5.0, I get the error `Parse error: Syntax Error: Cannot parse the unexpected character "\\".`
I logged just [before the error is thrown](https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js#L348) with `console.log(source)` which gave the output:
`$ ./node_modules/.bin/relay-compiler --src ./hello --schema ./schema.graphql `
```
HINT: pass --watch to keep watching for changes.
Source {
body: 'query HelloQuery {\\n allLinks {\\n id\\n url\\n }\\n}',
name: '/home/dan/projects/myapp5/hello/Hello.js',
locationOffset: { line: 2, column: 9 } }
ERROR:
Parse error: Syntax Error: Cannot parse the unexpected character "\\".
/home/dan/projects/myapp5/hello/Hello.js (2:27)
2: query HelloQuery {\n allLinks {\n id\n url\n }\n}
^
in "Hello.js"
```
It looks like, its escaping backslashes, even when the backslash should be considered part of an escape sequence (such as `\n`). It also seemed, by looking at the lexer source code, that it handled unicode line feed (`\u000a`) in the parser, but replacing `\n` with `\u000a`, had the same error.
Any thoughts?
Contributor guide
Assessment
This issue has not been assessed yet.