graphql-java-kickstart / graphql-java-tools

A schema-first tool for graphql-java inspired by graphql-tools for JS
https://www.graphql-java-kickstart.com/tools/
MIT License
812 stars 174 forks source link

Wrong Line Numbers in Parsing Errors #392

Open mxmp210 opened 4 years ago

mxmp210 commented 4 years ago

I was trying to implement Relay / Connection example, accidentally I made a mistake in schema file and console was giving parsing errors. It looked something like this :

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is graphql.parser.InvalidSyntaxException: Invalid Syntax : offending token '(' at line 9 column 17

My Schema Contains two root functions

type Query {
    suppliers(name: String, first: Int, after: String): SupplierConnection @connection(for: "Supplier")
    components(name: String, first: Int, after: String): ComponentConnection @connection(for: "Component")
}
....

While the error was on line 2, column 19 for not having space between argument and type, it was impossible to identify where the problem persisted because of not readable error outputs.

I know this is an old issue and needs reworks, and documentation assumes many things that user would know before starting, Is there any way to format errors at-least right so that it can be helpful?

vojtapol commented 4 years ago

How do you pass the schema into SchemaParser?

mxmp210 commented 4 years ago

How do you pass the schema into SchemaParser?

It is picked up by graphql-kickstart from .graphqls files in resources. I managed to find error in schema, it's not the problem, the problem is, if the schema is having minor errors like having spaces or typing mistake, line number would be completely different, making it almost impossible to find from looking at error code.

vojtapol commented 4 years ago

Absolutely, we will look into this.

Raf98 commented 2 years ago

Just had this error in a project. The problem is that the SchemaParser interprets all .graphqls files as a single file, that way, the column that is pointed is precise, but not the line, as it counts all the lines from other files parsed before, e.g., the line in which the error occurs is the line from the file plus an offset of all the lines already parsed from previous .graphql files.

mxmp210 commented 2 years ago

Just had this error in a project. The problem is that the SchemaParser interprets all .graphqls files as a single file, that way, the column that is pointed is precise, but not the line, as it counts all the lines from other files parsed before, e.g., the line in which the error occurs is the line from the file plus an offset of all the lines already parsed from previous .graphql files.

Agreed, although whole point of stack trace is to get back to origin. Giving lines in internal in memory file would be misleading as complex schemas would contain multiple files and tracing them would be very hard from given information.

This issue is stalled for so long already.