smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
159 stars 91 forks source link

How-to expose types from dependencies #1661

Closed abeggchr closed 1 year ago

abeggchr commented 1 year ago

How can types from dependent libraries or projects be exposed with smallrye-graphql? Currently I am getting the error message "type ... not found in schema".

Reproduce

  1. Create a new Quarkus GraphQL project quarkus create app org.acme:microprofile-graphql-quickstart --extension=quarkus-smallrye-graphql --no-code --gradle
  2. Modify build.gradle to have dependency implementation 'org.apache.commons:commons-math3:3.3'
  3. Create file src/main/java/Resource.java with content:
    
    import org.apache.commons.math3.stat.interval.ConfidenceInterval;
    import org.eclipse.microprofile.graphql.GraphQLApi;
    import org.eclipse.microprofile.graphql.Query;

@GraphQLApi public class Resource {

@Query
public ConfidenceInterval getConfidenceInterval() {
    return new ConfidenceInterval(1,2,3);
}

}

4. Start Quarkus

### Expected
Quarkus starts and the following query works `query { confidenceInterval { lowerBound } }`.

### Actual
I am getting the following stacktrace:

Caused by: java.lang.RuntimeException: Failed to start quarkus at io.quarkus.runner.ApplicationImpl.(Unknown Source) ... 15 more Caused by: graphql.AssertException: type ConfidenceInterval 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:109) at graphql.util.Traverser.traverse(Traverser.java:144) at graphql.schema.SchemaTraverser.doTraverse(SchemaTraverser.java:96) at graphql.schema.SchemaTraverser.depthFirst(SchemaTraverser.java:86)



### Versions used
quarkusPluginVersion=2.15.1.Final
quarkusPlatformVersion=2.15.1.Final
abeggchr commented 1 year ago

Reproduction repository: https://github.com/abeggchr/smallrye-grapqhql-expose-types

jmartisk commented 1 year ago

You need to explicitly tell Quarkus to add that dependency to the application index. Add this to your application.properties:

quarkus.index-dependency.math3.group-id=org.apache.commons
quarkus.index-dependency.math3.artifact-id=commons-math3

Let me know if this helps

jmartisk commented 1 year ago

I'll close this issue now as the solution was explained, please let me know if you have further questions

abeggchr commented 1 year ago

I can confirm that this worked. Thanks a lot.