adonis-graphql icon indicating copy to clipboard operation
adonis-graphql copied to clipboard

JS syntax errors in resolvers can be hard to track down

Open vthunder opened this issue 7 years ago • 2 comments

merge-graphql-schema's fileLoader uses require() to load js files. If a resolver contains a syntax error, all but the vaguest details get swallowed up (at least in my setup). No file name, no line number.

I'm filing it here in case you might be open to some kind of workaround. adonis-graphql calls fileLoader in the GraphQLServer constructor, so the upshot is that a single typo in a resolver causes a backtrace even for adonis -h:

$ adonis --help

SyntaxError: Unexpected token ,

1 anonymous /Users/thunder/node/tk-server/node_modules/merge-graphql-schemas/dist/index.cjs.js:3778

2 fileLoader /Users/thunder/node/tk-server/node_modules/merge-graphql-schemas/dist/index.cjs.js:3768

3 new GraphQLServer /Users/thunder/node/tk-server/node_modules/adonis-graphql/src/Server/index.js:17

4 Object.app.singleton [as closure] /Users/thunder/node/tk-server/node_modules/adonis-graphql/providers/GraphQLProvider.js:36

5 Ioc._resolveBinding /Users/thunder/node/tk-server/node_modules/@adonisjs/fold/src/Ioc/index.js:231

Happy to submit a PR if you think there's anything we could do in adonis-graphql to provide better errors when resolvers fail to load (e.g.: have not tried this, but this thread seems to suggest there are some private properties we might be able to fish out and print: https://github.com/nodejs/node/issues/12383 )

vthunder avatar Jan 11 '19 19:01 vthunder

Follow-up: I can confirm that wrapping the GraphQLServer constructor in a try/catch and simply printing exception.stack gets me the info I need (file & line number). No private properties required. So I'm using a locally hacked adonis-graphql so I can get that when I make a typo.

I'm not sure why that stack trace isn't being printed by default. Maybe this is a bug in some other adonis component that is catching & prettifying the stack trace?

vthunder avatar Jan 11 '19 20:01 vthunder

Hey @vthunder!

I'm not sure why that stack trace isn't being printed by default.

Same for me.

I'm happily accepting a PR that could help people having a proper stacktrace! 👍

RomainLanz avatar Jan 12 '19 08:01 RomainLanz