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
808 stars 174 forks source link

Hard to read debug info #224

Open ieugen opened 5 years ago

ieugen commented 5 years ago

Hello,

We are using graphql-java-tools 5.4.1 with DataLoader and we love it so far. One of the pain points we encountered is that it spits out some cryptic messages that we can't figure out how to solve.

For example we are working to add an input type JobProfileSurveySortBy and the class exists in our source code next to other types that are found.

It is also defined in the Resolver, however graphql-java-tools fails to find it. We don't know why and we don't have a workaround. These kind of issues pop up often. We know we have the java code and the schema files of since we implemented other types before.

We believe the issue lies with graphql-java-tools and how it searches for types.

They seem to go away if we make the library load the class by adding it into different places but that is more magic than science.

Any suggestions on how to fix this?

It would be great if the library provided more information on how it processes the schema files and what types it loads or some hints on where to push so we fix these errors.

Caused by: com.coxautodev.graphql.tools.SchemaError: Expected type 'JobProfileSurveySortBy' to be a GraphQLInputType, but it wasn't!  Was a type only permitted for object types incorrectly used as an input type, or vice-versa?
    at com.coxautodev.graphql.tools.SchemaParser.determineType(SchemaParser.kt:331) ~[graphql-java-tools-5.4.1.jar:na]

Thanks,

oliemansm commented 5 years ago

There's definitely some work to be done in that area.

In this particular case for input types it requires public getters to be able to find them properly (might also require the setters, not sure). Try adding those for now and see if that works out for you.

ieugen commented 5 years ago

Some more feedback regarding the hard to debug situation:

I've upgraded to graphql-spring-boot-starter 5.8.1 and my application fails to start with the following error:

[com/oembedler/moon/graphql/boot/GraphQLJavaToolsAutoConfiguration.class]: 
Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.coxautodev.graphql.tools.SchemaParser]: 
Factory method 'schemaParser' threw exception; 
nested exception is graphql.parser.InvalidSyntaxException: 
Invalid Syntax : offending token '}' at line 1290 column 0

It worked before this upgrade and I can't tell which file is to blame since I don't get that information or at least the offending line so I can git grep for it.

oliemansm commented 5 years ago

@ieugen There's no line 1290 in one of your SDL files? In 5.8.1 graphql-java has been updated to version 12. Sounds like their parser is more strict in this version.

ieugen commented 5 years ago

Hi, No there is no line 1290 in my files. From my knowledge the files are transformed / concatenated ?!

I've solved the issue. The parser was generating errors for empty extends like: extends type Query {}. I removed them and it worked ok.

The issue reported here still stands: the debug messages should be more meaningful - and give details to help find the cause. In my case I found the cause by debugging and checking the stacktrace. The cause is there (string snippet with the issue, but not in the logs :( .

bsara commented 5 years ago

@ieugen I just ran into this same issue after upgrading. I threw a breakpoint on line 183 of SchemaParserBuilder, then, using IntelliJ, I spit out the result of this.schemaString.toString() and pasted the string into into a temporary file. After you've done this, you can find the line specified in the logs. It's not a very straightforward way of getting to the bottom of the issue, but it works for the time being.

In my case, it's yelling at me because I have something like the following:

extend type Query {
  #futureField(...)
  #futureFields(...)
}

Just like was already reported, it doesn't seem to like empty extends.

bsara commented 5 years ago

Also of note, I have my schema spread across several files, which is why I had to use a debugger to get the full string used by the parser.

bsara commented 5 years ago

I've also just realized that, if you're using IntelliJ, the JS Graphql plugin is actually accurately identifying my syntax errors for me. I hadn't noticed it previously because things were running fine for me.

ieugen commented 5 years ago

Does the plugin work with Community edition? I know it requires JS support. I do have access to a license but I prefer to use community. Also for graphql editing I use Visual Studio Code.