question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When use string file path for typeDefs,there is a error: Cannot parse the unexpected character "/".

See original GitHub issue
const server = new GraphQLServer({
    typeDefs: './src/schema.graphql',
    resolvers,
})

When use string file path for typeDefs,there is a error: /Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/lexer.js:302 throw (0, _error.syntaxError)(source, pos, unexpectedCharacterMessage(code)); ^ GraphQLError: Syntax Error: Cannot parse the unexpected character “/”. at syntaxError (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/error/syntaxError.js:24:10) at readToken (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/lexer.js:302:32) at Object.lookahead (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/lexer.js:61:43) at Object.advanceLexer [as advance] (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/lexer.js:52:33) at expect (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/parser.js:1296:11) at parseDocument (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/parser.js:107:3) at Object.parse (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql/language/parser.js:38:10) at getDocumentFromSDL (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql-import/dist/index.js:107:26) at Object.importSchema (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql-import/dist/index.js:59:20) at mergeTypeDefs (/Users/harry/reactworkspace/graphql-yoga-server/hackernews-node/node_modules/graphql-yoga/dist/index.js:402:37)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:23

github_iconTop GitHub Comments

6reactions
tiagobnobregacommented, Mar 12, 2019

Same here… that’s strange. Maybe node version related. I worked around it by reading file contents and passing it to typedefs option, as if it was inlined in the code. Also I’m using “.graphqls” etension.

const typeDefs = fs.readFileSync('./src/schema.graphqls','utf8');
...
const server = new GraphQLServer({
  typeDefs,
  resolvers
});

I suspect it’s failing to reconize the argument as as filepath for some reason, so it tries to parse the path as actual graphql schema. Not why this happens though, I tried the same path for both fs.readFileSync and typeDefs option. I also tried the full path, but no luck either.

2reactions
AviIhejcommented, Nov 5, 2018

I am having the same issue… has anyone figured it out?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When I use string file path for typeDefs,there is a error: Cannot ...
When I use string file path for typeDefs,there is a error: Cannot parse the unexpected character "/". const server = new GraphQLServer({ ...
Read more >
GraphQLError: Syntax Error: Cannot parse the unexpected ...
While setting the server, connecting to mongodb database and doing a mutation, I'm getting following error after running node index.js .
Read more >
A brand new website interface for an even better experience!
When use string file path for typeDefs,there is a error: Cannot parse the unexpected character "/".
Read more >
Solved: Error while parsing JSON: 'Unexpected character en...
Error while parsing JSON: 'Unexpected character encountered while parsing value: A. Path '', line 0, position 0.' Need immediate help on this. Please...
Read more >
ParseJSON - The provided value cannot be parsed - Reddit
The provided value cannot be parsed: 'Unexpected character encountered while parsing value: R. Path '', line 0, position 0.'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found