I am new to GraphQL. However, after watching couple of videos and GraphQL blogs I decided to give it a try but I am getting "404 error" even after doing exactly the same thing as in those videos/blogs. Could this be because of "I am using a little newer version of Spring Boot than in those videos/blogs". Even this bare-bone example: https://github.com/shressur/spring-boot-and-graphql is not working. I would appreciate if anyone could guide me to the right direction.
QueryResolver.java
package com.example.demo.resolver;
import graphql.kickstart.tools.GraphQLQueryResolver;
public class QueryResolver implements GraphQLQueryResolver {
public String testingApp(){
return "Test in progress...";
}
}
learngraphql.graphqls
schema {
query: Query
}
type Query{
testingApp: String
}
dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.graphql</groupId>
<artifactId>spring-graphql-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>11.1.0</version>
</dependency>
</dependencies>
accessing graphiql:
http://localhost:8080/graphiql
query:
query{
testingApp
}
error:
{
"timestamp": "2022-05-01T17:49:04.825+00:00",
"status": 404,
"error": "Not Found",
"path": "/graphql"
}
@Component
on theQueryResolver
solved the issue (testing API successfully via Postman) – Shirberg