dangcuuson / graphql-schema-typescript

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

Getting GraphQLError: Syntax Error: Cannot parse the unexpected character #41

Closed netpoe closed 4 years ago

netpoe commented 4 years ago

When running graphql-schema-typescript generate-ts ./src/datamodel/testSchema.graphql --output ./src/datamodel/testSchema.d.ts from my package.json script:

"generate:schema": "graphql-schema-typescript generate-ts ./src/datamodel/testSchema.graphql --output ./src/datamodel/testSchema.d.ts"

I get the following error:

$ graphql-schema-typescript generate-ts ./src/datamodel/testSchema.graphql --output ./src/datamodel/testSchema.d.ts
Message:  null
Error:  GraphQLError: Syntax Error: Cannot parse the unexpected character ".".
    at syntaxError (/root/ziina/monorepo/graphqlserver/node_modules/graphql/error/syntaxError.js:15:10)
    at readToken (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/lexer.js:270:38)
    at Object.lookahead (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/lexer.js:54:43)
    at Object.advanceLexer [as advance] (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/lexer.js:44:33)
    at Parser.expectToken (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/parser.js:1399:19)
    at Parser.many (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/parser.js:1514:10)
    at Parser.parseDocument (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/parser.js:111:25)
    at parse (/root/ziina/monorepo/graphqlserver/node_modules/graphql/language/parser.js:36:17)
    at Object.buildSchema (/root/ziina/monorepo/graphqlserver/node_modules/graphql/utilities/buildASTSchema.js:462:43)
    at Object.<anonymous> (/root/ziina/monorepo/graphqlserver/node_modules/graphql-schema-typescript/lib/index.js:94:42) {
  message: 'Syntax Error: Cannot parse the unexpected character ".".',
  locations: [ { line: 1, column: 1 } ]
}
error Command failed with exit code 1.

I've tried with escaping double quotes, single quotes, etc. I've also tried to use the testSchema.graphql from the __tests__ to no avail.

Seems like a parse issue with the directory paths?

netpoe commented 4 years ago

@dangcuuson ?

QuestionAndAnswer commented 4 years ago

Has the same issue after adding union FullWidget = Widget | JSON

netpoe commented 4 years ago

Has the same issue after adding union FullWidget = Widget | JSON

@QuestionAndAnswer in my case, I ended up using: https://www.npmjs.com/package/@graphql-codegen/typescript-resolvers instead of this.

nathanbirrell commented 4 years ago

This is still an issue BTW