smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
160 stars 92 forks source link

Error on application startup: "graphql.AssertException: type FooDTO not found in schema" #2195

Closed vitomanuguerrasoft closed 1 month ago

vitomanuguerrasoft commented 1 month ago

I get this error trying to run my application:


java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:113)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:70)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
        ... 15 more
Caused by: graphql.AssertException: type FooDTO not found in schema
        at graphql.Assert.assertNotNull(Assert.java:17)
        at graphql.schema.GraphQLTypeResolvingVisitor.handleTypeReference(GraphQLTypeResolvingVisitor.java:49)
        at graphql.schema.GraphQLTypeResolvingVisitor.visitGraphQLTypeReference(GraphQLTypeResolvingVisitor.java:44)
        at graphql.schema.GraphQLTypeReference.accept(GraphQLTypeReference.java:62)
        at graphql.schema.SchemaTraverser$TraverserDelegateVisitor.enter(SchemaTraverser.java:111)
        at graphql.util.Traverser.traverse(Traverser.java:144)
        at graphql.schema.SchemaTraverser.doTraverse(SchemaTraverser.java:98)
        at graphql.schema.SchemaTraverser.depthFirst(SchemaTraverser.java:88)
        at graphql.schema.SchemaTraverser.depthFirst(SchemaTraverser.java:81)
        at graphql.schema.impl.SchemaUtil.replaceTypeReferences(SchemaUtil.java:105)
        at graphql.schema.GraphQLSchema$Builder.buildImpl(GraphQLSchema.java:938)
        at graphql.schema.GraphQLSchema$Builder.build(GraphQLSchema.java:904)
        at io.smallrye.graphql.bootstrap.Bootstrap.generateGraphQLSchema(Bootstrap.java:200)
        at io.smallrye.graphql.bootstrap.Bootstrap.bootstrap(Bootstrap.java:120)
        at io.smallrye.graphql.cdi.producer.GraphQLProducer.initialize(GraphQLProducer.java:52)
        at io.smallrye.graphql.cdi.producer.GraphQLProducer.initialize(GraphQLProducer.java:42)
        at io.smallrye.graphql.cdi.producer.GraphQLProducer.initialize(GraphQLProducer.java:32)
        at io.smallrye.graphql.cdi.producer.GraphQLProducer.initialize(GraphQLProducer.java:27)
        at io.smallrye.graphql.cdi.producer.GraphQLProducer_ClientProxy.initialize(Unknown Source)
        at io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLRecorder.createExecutionService(SmallRyeGraphQLRecorder.java:36)
        at io.quarkus.deployment.steps.SmallRyeGraphQLProcessor$buildExecutionService1691419614.deploy_12(Unknown Source)
        at io.quarkus.deployment.steps.SmallRyeGraphQLProcessor$buildExecutionService1691419614.deploy(Unknown Source)
        ... 16 more

The "FooDTO" is from an external dependency.

Quarkus version: 3.6.5

jmartisk commented 1 month ago

If the class is in an external dependency, you need to make sure that that dependency is added to the annotation index. You need to add these in your application.properties:

quarkus.index-dependency.EXTERNAL.group-id=MY_GROUP_ID
quarkus.index-dependency.EXTERNAL.artifact-id=MY_ARTIFACT_ID

(EXTERNAL is a logical name for the dependency, you can change that to whatever you want, MY_GROUP_ID and MY_ARTIFACT_ID need to be changed to the actual groupId and artifactId of your dependency)

jmartisk commented 1 month ago

Also, update your Quarkus version, 3.6.5 is very old and not LTS :)

vitomanuguerrasoft commented 1 month ago

@jmartisk Thank you for your response. With this configuration, everything is working perfectly now.