question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Startup: class java.lang.String cannot be cast to class graphql.schema.GraphQLDirective

See original GitHub issue

What version are you using? com.expediagroup:graphql-kotlin-spring-server:5.4.1

A clear and concise description of what the bug is. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'routerFunctionMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration$EnableWebFluxConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.expediagroup.graphql.server.spring.GraphQLRoutesConfiguration': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springGraphQLServer' defined in class path resource [com/expediagroup/graphql/server/spring/GraphQLSchemaConfiguration.class]: Unsatisfied dependency expressed through method 'springGraphQLServer' parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLRequestHandler' defined in class path resource [com/expediagroup/graphql/server/spring/GraphQLSchemaConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLRequestHandler' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQL' defined in class path resource [com/expediagroup/graphql/server/spring/GraphQLSchemaConfiguration.class]: Unsatisfied dependency expressed through method 'graphQL' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schema' defined in class path resource [com/expediagroup/graphql/server/spring/NonFederatedSchemaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception; nested exception is java.lang.ClassCastException: class java.lang.String cannot be cast to class graphql.schema.GraphQLDirective (java.lang.String is in module java.base of loader 'bootstrap'; graphql.schema.GraphQLDirective is in unnamed module of loader 'app')

Steps to reproduce the behavior. Create a base Spring Application - https://start.spring.io/ Minimal Setup via Tutorial With One Query - https://opensource.expediagroup.com/graphql-kotlin/docs/

A clear and concise description of what you expected to happen. Spring Application successful run? What I’m doing wrong? 😃

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dariuszkuccommented, Jun 6, 2022

Hello 👋 The underlying issue is that starting with Spring Boot 2.7.0 they (Spring Boot folks) started to manage graphql-java as one of their dependencies (which is used by the newly released spring-graphql package). TLDR they depend on graphql-java v18.1 whereas graphql-kotlin 5.x depends on v17.

Solutions are either to

  • use SpringBoot 2.6.x with graphql-kotlin 5.x (or simply use graphql-kotlin-spring-server which pulls in the appropriate Spring Boot libs)
  • use SpringBoot 2.7.x with graphql-kotlin 5.x but manually override the graphql-java version to v17
  • use SpringBoot 2.7.x with graphql-kotlin 6.x (final release has pending federation v2 changes)
Read more comments on GitHub >

github_iconTop Results From Across the Web

class java.lang.String cannot be cast to class graphql.schema ...
I was about to come here to report this bug. This is a very serious bug that basically completely breaks graphql-kotlin with Spring...
Read more >
Spring Boot GraphQLQueryResolver won't run, runs on test ...
It runs with the same Entity, Repository, Dependencies, application.properties on a new basic project just for testing the GraphQL. Does anybody ...
Read more >
Failed to start SpringBoot Application after addition of ... - GitHub
When you plan to Test (Spring Boot) using GraphQL API. You should add class path resources/application.propertices which address your .graphqls ...
Read more >
GraphQLSchema (graphql-java 0.0.0-2021-10-28T21 ... - javadoc.io
This returns the named directive that have been explicitly put on the schema object. java.util.Map<java.lang.String,GraphQLDirective>, getSchemaDirectiveByName ...
Read more >
Scalars | GraphQL Kotlin
IDs are serialized as a String . To expose a GraphQL ID field, you must use the com.expediagroup.graphql.generator.scalars.ID class, which is an inline ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found