Skip to content

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

Description

@ldiqual

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions