springspring-bootgraphqlnetflixnetflix-dgs

Getting error while using latest Netflix DGS bom in Springboot


I am trying out using the Netflix DGS library in Springboot, and have followed the documentation for getting started.

Current status is, if I am not including DGS as a dependency, application is working fine with Rest Controllers.

My aim is to build the Graphql application which does the following things at minimum:

When I am trying to run the application I am getting the following error:

2022-10-25 17:42:07.757  WARN 9856 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.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.NoSuchMethodError: graphql/schema/idl/RuntimeWiring.transform(Ljava/util/function/Consumer;)Lgraphql/schema/idl/RuntimeWiring; (loaded from file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@5828c5f9) called from class com.apollographql.federation.graphqljava.Federation (loaded from file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.apollographql.federation/federation-graphql-java-support/2.1.0/9ef0abf955406d2573e84990c05bc3fcb4b2404a/federation-graphql-java-support-2.1.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@5828c5f9).
2022-10-25 17:42:07.762  INFO 9856 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-10-25 17:42:07.788  INFO 9856 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-10-25 17:42:07.810 ERROR 9856 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

com.apollographql.federation.graphqljava.Federation.ensureFederationDirectiveDefinitionsExist(Federation.java:194)

The following method did not exist:

        graphql/schema/idl/RuntimeWiring.transform(Ljava/util/function/Consumer;)Lgraphql/schema/idl/RuntimeWiring;

The calling method's class, com.apollographql.federation.graphqljava.Federation, was loaded from the following location:

jar:file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.apollographql.federation/federation-graphql-java-support/2.1.0/9ef0abf955406d2573e84990c05bc3fcb4b2404a/federation-graphql-java-support-2.1.0.jar!/com/apollographql/federation/graphqljava/Federation.class

The called method's class, graphql.schema.idl.RuntimeWiring, is available from the following locations:

jar:file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar!/graphql/schema/idl/RuntimeWiring.class

The called method's class hierarchy was loaded from the following locations:

graphql.schema.idl.RuntimeWiring: file:<HOME_DIR>/.gradle/caches/modules-2/files-2.1/com.graphql-java/graphql-java/18.3/d30b46b4db4818fc6547d233b7aef5af6dcfe715/graphql-java-18.3.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.apollographql.federation.graphqljava.Federation and graphql.schema.idl.RuntimeWiring


        > Task :InventoryApplication.main() FAILED

Followning is the build.gradle that I am using:

plugins {
    id 'org.springframework.boot' version '2.7.5'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
    id 'java'
    id "com.netflix.dgs.codegen" version "5.2.4"
    id "org.sonarqube" version "3.4.0.2513"
}

sonarqube {
    properties {
        property "sonar.projectKey", "ArvindSinghRawat_E-Commerce-Inventory"
        property "sonar.organization", "e-commerce"
        property "sonar.host.url", "https://sonarcloud.io"
    }
}

generateJava {
    schemaPaths = ["${projectDir}/src/main/resources/schema"]
    // List of directories containing schema files
    packageName = 'com.personal.inventory.dto.graphql'
    // The package name to use to generate sources
    generateClient = false // Enable generating the type safe query API
    typeMapping = ["BigDecimal": "java.math.BigDecimal"]
}

compileJava {
    options.compilerArgs += ['-Amapstruct.defaultComponentModel=spring',
                             '-Amapstruct.defaultInjectionStrategy']
}

group = 'com.personal'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

ext['kotlin.version'] = '1.4.31'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
//    GraphQL dependencies
    implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release"))
    implementation "com.netflix.graphql.dgs:graphql-dgs-webflux-starter"
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
    implementation 'org.mapstruct:mapstruct:1.5.3.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
    testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
}

tasks.named('test') {
    useJUnitPlatform()
}

Please do let me know, if I am missing out on something.


Solution

  • Try to add to your gradle build script next lines:

    dependencyManagement {
        imports {
            mavenBom 'com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release'
        }
    }
    

    Check issue about the problem: https://github.com/Netflix/dgs-framework/issues/1281#issuecomment-1284694300