graphql-js: Unclear Error Output on Language/Parser.js

I’m assuming I introduced the following error, but it seems to originate deep within the module and is not clear on exactly what it is that’s failing

/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:966 throw (0, _error.syntaxError)(lexer.source, token.start, 'Expected ' + kind + ', found ' + (0, _lexer.getTokenDesc)(token)); ^ GraphQLError at syntaxError (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/error/syntaxError.js:28:15) at expect (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:966:32) at parseFieldDefinition (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:715:3) at any (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:1002:16) at parseObjectTypeDefinition (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:683:16) at parseTypeSystemDefinition (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:607:16) at parseDefinition (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:148:16) at parseDocument (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:106:22) at parse (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/language/parser.js:43:10) at buildSchema (/home/zmg/Thinkful/Goalzapp/server/node_modules/graphql/utilities/buildASTSchema.js:461:43) at Object.<anonymous> (/home/zmg/Thinkful/Goalzapp/server/index.js:15:16) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@leebyron

I’m able to repro this in one instance:

Naively, I removed an argument from one of the sub-types in my schema but left the parens, like this:

type RootQuery {
  viewer(webtoken: String!): User
  user(): User
  users: [User] 
  item(_id: String!): Item 
  items(menuCategory: MenuCategory): [Item] 
  allItems: [Item]
  order(_id: String!): Order 
  allOrders (): [Order] 
  menu: Menu
}

Notice users and allOrders. Removing the offending empty parens fixes the error below:

node_modules/graphql/language/parser.js:966
  throw (0, _error.syntaxError)(lexer.source, token.start, 'Expected ' + kind + ', found ' + (0, _lexer.getTokenDesc)(token));
  ^
GraphQLError
    at syntaxError (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/error/syntaxError.js:28:15)
    at expect (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:966:32)
    at parseName (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:88:15)
    at parseInputValueDef (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:743:14)
    at many (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:1015:16)
    at parseArgumentDefs (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:735:10)
    at parseFieldDefinition (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:714:14)
    at any (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:1002:16)
    at parseObjectTypeDefinition (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:683:16)
    at parseTypeSystemDefinition (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:607:16)
    at parseDefinition (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:148:16)
    at parseDocument (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:106:22)
    at Object.parse (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql/language/parser.js:43:10)
    at buildSchemaFromTypeDefinitions (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql-tools/src/schemaGenerator.ts:158:19)
    at _generateSchema (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql-tools/src/schemaGenerator.ts:72:18)
    at makeExecutableSchema (/Users/marcfawzi/c0de/graffalojs/server/node_modules/graphql-tools/src/schemaGenerator.ts:97:20)
    at Function.module.exports (/Users/marcfawzi/c0de/graffalojs/server/services/graphql/index.js:12:28)
    at Function.configure (/Users/marcfawzi/c0de/graffalojs/server/node_modules/feathers/lib/application.js:138:8)
    at Function.module.exports (/Users/marcfawzi/c0de/graffalojs/server/services/index.js:23:7)
    at Function.configure (/Users/marcfawzi/c0de/graffalojs/server/node_modules/feathers/lib/application.js:138:8)
    at Object.<anonymous> (/Users/marcfawzi/c0de/graffalojs/server/app.js:30:4)
    at Module._compile (module.js:571:32)
    at loader (/Users/marcfawzi/c0de/graffalojs/server/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/marcfawzi/c0de/graffalojs/server/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
error Command failed with exit code 1.

thanks alot @idibidiart

type LaunchConnection {
    cursor: String!
    hasMore: Boolean
    launches:  
}

issue in my case was that i didn’t add a type for lauches after the colon. expected graphql to have pointed me to where my error is coming from though, instead, i its points to a line parser.js

your answer pointed me to the right direction 😎

Strange that you’re not seeing the message of the syntax error, which is what I see when I run a test like require('graphql').parse('{{'):

GraphQLError: Syntax Error: Expected Name, found {

Also, if you’re calling parse() directly, then I recommend catching the parser errors and handling them in a more convenient way, such as:

try {
  return parse(text);
} catch (syntaxError) {
  console.error('Failed to parse the GraphQL document.\n' + syntaxError);
  process.exit(1);
}