Closed Erando89 closed 3 months ago
Hum,
If I understand well, you executed these steps:
Right ?
Then did you also copy the generated resources folder ? It contains an autoconfiguration spring files, that is mandatory to make this work.
Etienne
Any update ?
Hi Etienne,
during a migration from Spring Boot 2 to 3, I am currently upgrading from version 1.18.9 to 2.4. I have meticulously followed your migration steps and reviewed all example configurations. Unfortunately, I am encountering a similar problem to Erando89. All files could be compiled and code generation works. However, when starting the application, I get this exception:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field springContextBean in de.myCompany.myProject.gitlab.spring_autoconfiguration.GraphQLPluginAutoConfiguration required a bean of type 'com.graphql_java_generator.client.SpringContextBean' that could not be found.
Action:
Consider defining a bean of type 'com.graphql_java_generator.client.SpringContextBean' in your configuration.
This is my build.gradle:
buildscript {
ext {
azureVersion = '2.2.5'
springBootVersion = '3.2.1'
springCoreVersion = '6.1.8'
springSecurityVersion = '6.2.4'
graphQLPluginVersion = '2.4'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-starter-graphql:${springBootVersion}"
}
}
plugins {
id "com.graphql-java-generator.graphql-gradle-plugin3" version "${graphQLPluginVersion}"
id 'idea'
id 'java'
id 'org.springframework.boot' version "${springBootVersion}"
id 'io.spring.dependency-management' version '1.1.5'
id 'org.owasp.dependencycheck' version '7.4.4'
}
apply from: 'graphql.gradle' //applies generateClientCodeConf
dependencies {
implementation "org.springframework.boot:spring-boot:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-security:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-validation:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-graphql:${springBootVersion}"
implementation "com.graphql-java-generator:graphql-java-client-runtime:${graphQLPluginVersion}"
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
testImplementation "org.springframework.security:spring-security-test:${springSecurityVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.2"
testImplementation "org.mockito:mockito-junit-jupiter:4.11.0"
}
sourceSets.main.java.srcDirs += '/build/generated/sources/graphqlGradlePlugin'
sourceSets.main.resources.srcDirs += '/build/generated/resources/graphqlGradlePlugin'
The only thing i changed in the code is, to create a graphQlClient...
@Bean
public GraphQlClient graphQlClient(WebClient webClient) {
return HttpGraphQlClient.builder(webClient)
.build();
}
Because for some reason, since the version change, the builder no longer only requires the GraphQlRequest.class but also a GraphQlClient to use withQueryResponseDef:
private ObjectResponse getObjectResponse(String queryResponseDef) throws GraphQLRequestPreparationException {
return new Builder(graphQlClient, GraphQLRequest.class).withQueryResponseDef(queryResponseDef).build();
}
It would be great if you could check that out.
Best regards Thomas
Hello,
Thanks to your detailed info, I'll try to repeat this issue.
Currently, I'm having a hard time just compiling the project. My PC seems to be quite reluctant about your gradle conf :(
Yes it definitely doesn't want : I upgraded java to version 21, gradle to 8.8, and I'm back to this error : Could not resolve all artifacts for configuration ':detachedConfiguration1'.
I'll keep on testing tomorrow
No hurry. If you have found a working combination of a gradle configuration, I would be very happy. It doesn't necessarily have to be the very latest Java, gradle or Spring version.
I am very glad that you want to solve the problem.
In case you need the graphql.gradle to run everything here it is:
generateClientCodeConf {
schemaFileFolder = 'src/main/resources/graphql/gitlab'
packageName = 'de.myCompany.myProject.gitlab'
copyRuntimeSources = false
generateDeprecatedRequestResponse = false
separateUtilityClasses = true
customScalars =
[
[
graphQLTypeName : "AlertManagementHttpIntegrationID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "AwardableID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "BoardID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CiBuildID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CiJobArtifactID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CiPipelineID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CiPipelineScheduleID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CiRunnerID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ClustersAgentID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ClustersAgentTokenID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ClustersClusterID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ContainerRepositoryID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CustomEmojiID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CustomerRelationsContactID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CustomerRelationsOrganizationID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DependencyProxyManifestID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DesignManagementDesignAtVersionID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DesignManagementDesignID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DesignManagementVersionID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DiffNoteID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "DiscussionID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "EnvironmentID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "GitlabErrorTrackingDetailedErrorID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "GlobalID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "GroupID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "IncidentManagementTimelineEventID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "IntegrationsPrometheusID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "IssuableID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "IssueID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "JobID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "CommitStatusID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "LabelID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ListID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "MergeRequestID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "MetricsDashboardAnnotationID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "MilestoneID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "NoteID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "NoteableID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesConanFileMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesConanMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesDependencyID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesDependencyLinkID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesMavenMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesNugetDependencyLinkMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesNugetMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesPackageFileID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesPackageID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "PackagesPypiMetadatumID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ProjectID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ReleaseID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "ReleasesLinkID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "SnippetID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "TerraformStateID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "TimelogID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "TodoID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "TodoableID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "UploadID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "UserID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "UsersSavedReplyID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "IssueID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "WorkItemID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "WorkItemsTypeID",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "BigInt",
javaType : "java.math.BigInteger",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "Color",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "Date",
javaType : "java.util.Date",
graphQLScalarTypeStaticField: "com.graphql_java_generator.customscalars.GraphQLScalarTypeDate.Date"
],
[
graphQLTypeName : "Duration",
javaType : "java.lang.Float",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLFloat"
],
[
graphQLTypeName : "ISO8601Date",
javaType : "java.util.Date",
graphQLScalarTypeStaticField: "com.graphql_java_generator.customscalars.GraphQLScalarTypeDate.Date"
],
[
graphQLTypeName : "JSON",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "Time",
javaType : "java.util.Date",
graphQLScalarTypeStaticField: "com.graphql_java_generator.customscalars.GraphQLScalarTypeDateTime.DateTime"
],
[
graphQLTypeName : "UntrustedRegexp",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
[
graphQLTypeName : "Upload",
javaType : "java.lang.String",
graphQLScalarTypeStaticField: "graphql.Scalars.GraphQLString"
],
]
}
Hi Etienne, i have solved this Problem...
Field springContextBean in de.myCompany.myProject.gitlab.spring_autoconfiguration.GraphQLPluginAutoConfiguration required a bean of type 'com.graphql_java_generator.client.SpringContextBean' that could not be found.
Action: Consider defining a bean of type 'com.graphql_java_generator.client.SpringContextBean' in your configuration.
with the ComponentScan Annotation on of my config-classes:
@ComponentScan(basePackages = { "com.graphql_java_generator.client" })
I think that the classes that were autogenerated could not call the SpringContextBean of the client library. Unfortunately, I have other problems with the migration. I will rebuild my project so that I can publish it on Gitlab and keep you in the loop.
Hello,
I created a project from your ´build.gradle´ and ´graph.gradle´ files.
But I could not locate this code (that you provided):
´´´ java private ObjectResponse getObjectResponse(String queryResponseDef) throws GraphQLRequestPreparationException { return new Builder(graphQlClient, GraphQLRequest.class).withQueryResponseDef(queryResponseDef).build(); } ´´´
From where did you copy this code ?
Étienne
Sorry for the confusion. The code was written by myself in my project and uses your builder constructor. I thought the changes in your new Builder
-constructor where responsible for the problem mentioned above i was able to fix the original problem by setting the correct annotation:
@SpringBootApplication(scanBasePackageClasses = { Application.class, GraphqlClientUtils.class, QueryExecutor.class })
I was unable to reproduce @Erando89's error. Maybe he forgot the correct Annotation too. From my point of view, this issue can be closed.
Right, ok.
That explains why I didn't find this code.
BTW, I don't understand why you had to create a GraphQlClient
yourself. The plugin generates a spring autoconfiguration file, that creates the needed GraphQlClient. So you should not have to create it yourself. Please note that:
httpGraphQlClientAllGraphQLCases
are created: httpGraphQlClient
(for queries and mutations) and webSocketGraphQlClient
(for subscriptions)GraphQlClient
are suffixed with this bean suffixI added a note in my todo list, to check that this is properly documented.
Etienne
Hi Étienne, thank you for your hard work on this project. I followed your Client Gradle tutorial and ran in some problems which I'm not sure you're aware of.
I used your plugin successfully to generate a client of a GraphQL API (using Spring Boot 2.4.4 btw). I copied all generated files into my project and added one dependency:
implementation "com.graphql-java-generator:graphql-java-client-runtime:2.4"
Thus all files could get compiled. When starting the application though I get this exception and the app terminates:
Thank you for looking into this.
Best regards