I want to integrate Graphql in my project. I started with a new Spring boot project following (several) tutorial but none of them are working: the graphql endpoint does not appear, it seems that the graphqls file is not detected?
My project is a Maven project with following dependencies:
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.10.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.6.1</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.10.0</version>
<scope>runtime</scope>
</dependency>
To keep the post brief, I tried to put only the relevant dependencies avoiding the others (Lombok, jpa, etc...)
And my graphqls file (in resources folder):
type Vehicle {
id: ID!,
type: String,
modelCode: String,
brandName: String,
launchDate: String
}
type Query {
vehicles(count: Int):[Vehicle]
vehicle(id: ID):Vehicle
}
type Mutation {
createVehicle(type: String!, modelCode: String!, brandName: String, launchDate: String):Vehicle
}
According to the documentation, the graphql endpoint should be created since I have a graphql-spring-boot-starter dependency and a schema which will be created automatically with my vehicle.graphqls file (and the graphql-java-tools dependency)
The servlet becomes accessible at /graphql if graphql-spring-boot-starter added as a dependency to a boot application and a GraphQLSchema bean is present in the application [...] A GraphQL schema can also be automatically created when a supported graphql-java schema library is found on the classpath.
The only way I made the graphql endpoint appearing is by creating a schema programmatically (which I want to avoid):
@Bean
GraphQLSchema schema() {
return GraphQLSchema.newSchema()
.query(GraphQLObjectType.newObject()
.name("query")
.field(field -> field
.name("test")
.type(Scalars.GraphQLString)
.dataFetcher(environment -> "response")
)
.build())
.build();
}
I guess that I missed something but after one day of attempts, I am now stuck, I don't see what can be my mistake.
GraphQLResolverin my case) are implemented for searching. But since I use thecom.graphql-java-kickstart.graphql-java-tool, I should not have to write this GraphQLProvider as withcom.graphql-java.graphql-java. But I may have miss your point?kickstartpackage is supposed to handle that for you, I suppose not.graphql.servlet.enabled=true