js-graphql-intellij-plugin
js-graphql-intellij-plugin copied to clipboard
Interface fields implementation with missing default values
Hi, I have a question about suppressing or fixing parsing errors in a schema. Currently there is only 4 lines that cause parsing error which prevents use of entire plugin. I can manually delete, but hard to encourage my team to use a plugin that requires this kind of a hack, and makes it annoying to auto-update my schema. Is there a way to prevent a few lines from breaking the schema validation step if they are known ahead of time?
I am also having this issue - a false error prevents all graphql environments from working. Any way around it?
Hi! What kind of error is it exactly? I've done a lot of things to prevent similar issues in the upcoming v3 release, but I'm not sure if this is your case due to the lack of details.
@SriwanKm What do you mean by "parsing error"? Is this syntactically incorrect code or just something that is not supported by the plugin at the moment? Or is it a schema error?
@vepanimas
I am not sure, I think it is just the plugin not supporting the way we designed the schema in one place. That one failure has been a major blocker for us to use the plugin for years. I have to manually delete the one interface field that is catching the error after every time I update the schema through introspection, but in order to add it as a required plugin for all the devs at my company and be able to update the schema on the fly I need to figure out how to fix this parsing error in one field.
It looks like it doesn't like the way we are implementing this one interface called ImageInterfaceType. I was hoping there was a workaround, I even tried to fork the plugin but I wasn't able to make the schema pass the validation step after months of trying. It would be amazing if I could finally offer the huge benefit this plugin provides to my team and other devs at my company. Thanks!
`"Color information about the image"
color_profile(
"Height to crop the image before extracting dominant color"
crop_height: PositiveInt = 250,
"Width to crop the image before extracting dominant color"
crop_width: PositiveInt = 250,
"Height to resize the image before extracting dominant color"
resize_height: PositiveInt = 250,
"Width to resize the image before extracting dominant color"
resize_width: PositiveInt = 250
): ColorProfile`
This is the field it doesn't like, it is defined once in ImageInterfaceType and then there are a few other classes that implement that interface that all have the exact same lines, but according to the error, it says they are "defined differently" and therefore does not implement the interface properly. I solved it by just deleting the color_profile field from the interface, then all the implementing classes no longer throw this error.
graphql.schema.validation.InvalidSchemaException: invalid schema: object type 'Image' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_height' is defined differently object type 'Image' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_width' is defined differently object type 'Image' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_height' is defined differently object type 'Image' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_width' is defined differently object type 'STLPhoto' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_height' is defined differently object type 'STLPhoto' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_width' is defined differently object type 'STLPhoto' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_height' is defined differently object type 'STLPhoto' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_width' is defined differently object type 'SmartPhotoImage' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_height' is defined differently object type 'SmartPhotoImage' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'crop_width' is defined differently object type 'SmartPhotoImage' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_height' is defined differently object type 'SmartPhotoImage' does not implement interface 'ImageInterfaceType' because field 'color_profile' argument 'resize_width' is defined differently at graphql.schema.GraphQLSchema$Builder.buildImpl(GraphQLSchema.java:571) at graphql.schema.GraphQLSchema$Builder.build(GraphQLSchema.java:546) at graphql.schema.idl.SchemaGenerator.makeExecutableSchemaImpl(SchemaGenerator.java:283) at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:257) at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:227) at graphql.schema.idl.UnExecutableSchemaGenerator.makeUnExecutableSchema(UnExecutableSchemaGenerator.java:28) at com.intellij.lang.jsgraphql.schema.GraphQLSchemaProviderImpl.lambda$getValidatedSchema$3(GraphQLSchemaProviderImpl.java:71) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) at com.intellij.lang.jsgraphql.schema.GraphQLSchemaProviderImpl.getValidatedSchema(GraphQLSchemaProviderImpl.java:66) at com.intellij.lang.jsgraphql.ide.project.schemastatus.GraphQLConfigSchemaNode.<init>(GraphQLConfigSchemaNode.java:90) at com.intellij.lang.jsgraphql.ide.project.schemastatus.GraphQLSchemasRootNode.getChildren(GraphQLSchemasRootNode.java:48) at com.intellij.lang.jsgraphql.ide.project.schemastatus.GraphQLSchemasPanel.lambda$createTreePanel$0(GraphQLSchemasPanel.java:128) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:825) at com.intellij.lang.jsgraphql.ide.project.schemastatus.GraphQLSchemasPanel.lambda$createTreePanel$1(GraphQLSchemasPanel.java:125) at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20) at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11) at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:271) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665) at java.base/java.lang.Thread.run(Thread.java:834)
If you could help me to make the plugin understand our schema in the official version or a forked one, or suppress the one error, or any other suggestions you might have, would be so grateful, this has been frustrating me for a good while!

Okay, so the reason is the default values. It's great that it now works for you. I'll take another look at whether we should check the default values when checking interface implementations or not, I'm not sure about that.
@vepanimas Thanks! Yeah it makes me think that this checkbox should probably be set to default disabled instead of default enabled. I am afraid there are a lot of other people in similar situation who aren't as stubborn as me and just assume the plugin is broken when they only need to uncheck this box to get it to work. It might be better to err on the side of basic functionality then trying to get all the bells and whistles and not working for a lot of people.
My story is a good example, since I only figured out after a long process, first by manually editing the schema where the parsing errors where located, then stumbling across the checkbox in the settings menu. I remember for the first year I download the plugin, I didn't even know that the plugin can do more than just add a file association for .graphql files, and everything was red, then one day I fixed the schema and it magically started working. Then I spent another year trying to fix the schema so I don't have to manually edit it and can make it a required plugin for Android at my company.
Also I am still looking into why the default values on that particular interface (even when removed) don't play nice with the parser. Of course if I could fix it from the schema then I could re-enable use of default values which would be nice.
Only this case is considered a valid implementation, both interface and implementor fields must have the same default values:
interface I {
field(s: String = "default"): String
}
type T implements I {
field(s: String = "default"): String
}
This would be reported as an error:
interface I {
field(s: String = "default"): String
}
type T implements I {
field(s: String): String
}
I'm not sure if we should check the default values while checking the fields, I'll figure it out.