I wrote a simple GraphQL Servlet based on class SimpleGraphQLServlet
. The constructor of this class is deprecated and it is recommended to use the builder instead. So what I did is to provide my own servlet which forwards the requests to an instance of SimpleGraphQLServlet
which can be builded in my servlet's init
method:
@WebServlet("/graphql")
public class GraphQLEndpoint extends HttpServlet {
SimpleGraphQLServlet graphQLServlet;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
graphQLServlet.service(req, resp);
}
@Override
public void init() throws ServletException {
graphQLServlet = SimpleGraphQLServlet.builder(buildSchema()).withInstrumentation(new TracingInstrumentation()).build();
}
private GraphQLSchema buildSchema() { /* ... */ }
}
However, when the SimpleGraphQLServlet
instance is created, the following exception is thrown:
java.lang.NoClassDefFoundError: graphql/execution/instrumentation/NoOpInstrumentation
at graphql.servlet.SimpleGraphQLServlet$Builder.<init>(SimpleGraphQLServlet.java:134) ~[graphql-java-servlet-4.7.0.jar:na]
which is strange as the class seems to be available in the jar file graphql-java-8.0.jar
. I declared the following dependencies:
dependencies {
compile "com.graphql-java:graphql-java:8.0"
compile "com.graphql-java:graphql-java-tools:4.3.0"
compile "com.graphql-java:graphql-java-servlet:4.7.0"
compile "org.slf4j:slf4j-simple:1.7.25"
testCompile "junit:junit:3.8.1"
providedCompile "javax.servlet:javax.servlet-api:3.0.1"
}
What did I miss?
I did receive a hint from @kaqqao who informed me, that my exception is a graphql-java version mismatch. Version 8.0 which I was using is not yet compatible.
Now I use the following graphql-java dependencies, and it works fine:
compile "com.graphql-java:graphql-java:7.0"
compile "com.graphql-java:graphql-java-tools:4.3.0"
compile "com.graphql-java:graphql-java-servlet:4.7.0"
@kaqqao closed with the comment "Overriding dependency versions is scary business.". I agree ;-)