dangcuuson / graphql-schema-typescript

Generate TypeScript from GraphQL's schema type definitions
191 stars 36 forks source link

Fails with wrong error when graphql file has syntax error #42

Open ldiqual opened 4 years ago

ldiqual commented 4 years ago

When trying to generate typescript code from an invalid graphql file:

$ graphql-schema-typescript generate-ts generate-ts src/chema.graphql
Message:  null
Error:  { GraphQLError: Syntax Error: Cannot parse the unexpected character "/".
    at syntaxError (/Users/ldiqual/Siteline/siteline/node_modules/graphql/error/syntaxError.js:15:10)
    at readToken (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/lexer.js:270:38)
    at Object.lookahead (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/lexer.js:54:43)
    at Object.advanceLexer [as advance] (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/lexer.js:44:33)
    at Parser.expectToken (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/parser.js:1398:19)
    at Parser.many (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/parser.js:1514:10)
    at Parser.parseDocument (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/parser.js:111:25)
    at parse (/Users/ldiqual/Siteline/siteline/node_modules/graphql/language/parser.js:36:17)
    at Object.buildSchema (/Users/ldiqual/Siteline/siteline/node_modules/graphql/utilities/buildASTSchema.js:462:43)
    at Object.<anonymous> (/Users/ldiqual/Siteline/siteline/node_modules/graphql-schema-typescript/lib/index.js:98:42)
  message: 'Syntax Error: Cannot parse the unexpected character "/".',
  locations: [ { line: 1, column: 1 } ] }

What happens is that https://github.com/dangcuuson/graphql-schema-typescript/blob/master/src/index.ts#L53 parses the schema file from a path, and it throws because there's a syntax error, but then the error is silenced and the code tries to parse the actual path string, which results in the error above.

thanhdongnguyen commented 4 years ago

This is deviated version of graphql. Downgrade version suit with graphql-schema-typescript. Example my version graphql-schema-typescript is 1.2.9, i use graphql version 14.0.1

gabsprates commented 4 years ago

Same problem here. It would be good update graphql dependency version