I am learning graphql and facing some issue in the local with hello-world level project code. Can you please help me on it.
Given the below details, I am able to build and run the application without any errors. But when I hit the urls localhost:8080/graphiql(in browser) or localhost:8080/graphql(in AltAir plugin), I am getting 404 as reponse (Whitelabel error page). Can you please help me on this. Thanks in advance.
Details
- I am using Java 17 as runtime.
- Spring boot version : 3.2.1
- Maven dependencies.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
- Query Class
@Component
public class Query implements GraphQLQueryResolver {
public String firstName() {
return "Sankar";
}
}
- Graphql schema file (query.graphqls)
type Query{
firstName : String
}
I guess it is caused by incorrect dependencies for GraphQL support.
I used Spring Initializr and it provides the following dependency in the
pom.xml
of generated project:Please, try to remove
com.graphql-java
dependencies and use the above instead or better generate a newpom.xml
using Initializr for your project.And one more thing to check for
graphiql
endpoint: in order to make it work, addspring.graphql.graphiql.enabled: true
intoapplication.yml
of the project.