Unable to access GraphQL server and GraphiQL
sachink-2020 opened this issue · 7 comments
I am always having issue while launching the URL "http://localhost:8020/test" for graphql. My server is started.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Oct 08 11:14:21 EDT 2020
There was an unexpected error (type=Not Found, status=404).
Here are my application.properties
spring.application.name=demo-graphql
server.port=8020
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=SA
spring.datasource.password=
graphql.url=/test
graphql.servlet.enabled=true
graphiql.endpoint=/test
graphiql.mapping=/graphiql
gradle dependencies
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '9'
repositories {
mavenCentral()
}
dependencies {
compile 'com.graphql-java-kickstart:graphql-java-servlet:7.4.0'
compile 'com.graphql-java:graphql-java-servlet:4.6.1'
implementation 'com.graphql-java:graphql-java:15.0'
implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:7.0.1'
implementation 'com.graphql-java-kickstart:graphql-java-servlet:9.1.0'
implementation 'com.graphql-java-kickstart:graphql-java-tools:5.6.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Below is the error as well
IdeaProjects\demo-graphql\src\main\java\com\example\demo\exception\GraphQLErrorAdapter.java:31: error: incompatible types: Erro
rClassification cannot be converted to ErrorType
return error.getErrorType();
How to fix it?
Hi @sachink-2020,
This project is based on an old version of spring-boot and graphql-java, I see you're using newer versions of these libraries so, in some parts, the code will not be compatible.
In the project, the method getErrorType()
from GraphQLErrorAdapter
returns the enum ErrorType, but now, this enum implements the interface ErrorClassification.
Looking at the code of GraphQLError, the interface implemented by GraphQLErrorAdapter
, you can see that now returns ErrorClassification
, so probably just changing the type can fix the error.
I haven't worked with Java and GraphQL for years, so I'm not aware of all the modifications and features of the newer versions, I'm sorry I can't be of more help.
Do you have a gradle project?
No, sorry.
Well, I don't know someone in particular, but some people follow this repo, maybe one of them can help you. I have also applied the help wanted
label to this issue.
But, what if you disable the custom exception handling? Just comment out the errorHandler()
method in the class DemoGraphQlApplication
. This should eliminate the error and after that, maybe the application can be deployed correctly.
You can also check out other tutorials (more recent tutorials):
- https://www.baeldung.com/spring-graphql
- https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/
- https://medium.com/@tiagoamp/graphql-with-java-and-spring-boot-a081839122ad
And in this repo you can find some examples.
Hope this helps.
Can you share your project (removing any secrests) on github/gitlab/bibucket? I would like to give it a try and fix it for you.
If you have already got the solution, I would be pleased if you share your solution here and close the issue.
Thanks.
Looking at your application.properties
I would like to highlight one thing here.
As I've seen, you are mapping /test
as graphql endpoint and /graphiql
as graphiql (basically the UI/Playground) but you are visiting /test
from your browser/client.
Actually, graphql endpoint (/test
in your case) is a POST
API. And from your browser, you make GET
call to http://localhost:8020/test
. This will always result in 404
in my guess. You should try http://localhost:8020/graphiql
once, and I believe it should work as you expect.
I would be happy to know if it helped. :)