spring boot starter graphql not working
Asked Answered
S

3

8

I recently started working with graphql and found it very intriguing. Since most of my rest apps were in java, I decided to do a quick setup using the provided spring boot starter project by the graphql-java team. It comes with graph-iql autoconf spring setup, which makes it easier to query /graphql endpoint.

After spending a few good hours on the project setup in IDEA, I was able to run the graphql-sample-app. But I think my servlet is still not enabled, and only the graphiql endpoint is running, as the default query is returning 404.

This is application.yml:

spring:
      application:
               name: graphql-todo-app
server:
      port: 9000

graphql:
      spring-graphql-common:
               clientMutationIdName: clientMutationId
               injectClientMutationId: true
               allowEmptyClientMutationId: false
               mutationInputArgumentName: input
               outputObjectNamePrefix: Payload
               inputObjectNamePrefix: Input
               schemaMutationObjectName: Mutation
      servlet:
             mapping: /graphql
             enabled: true
             corsEnabled: true

graphiql:
    mapping: /graphiql
    enabled: true

This is what my build.gradle file looks like:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url 'http://repo.spring.io/plugins-release' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6"
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

repositories {
    jcenter()
    mavenCentral()
}

dependencies{
//    compile(project(":graphql-spring-boot-starter"))
//    compile(project(":graphiql-spring-boot-starter"))
    compile 'com.graphql-java:graphql-spring-boot-starter:3.6.0'

    // to embed GraphiQL tool
    compile 'com.graphql-java:graphiql-spring-boot-starter:3.6.0'

    compile "com.embedler.moon.graphql:spring-graphql-common:$LIB_SPRING_GRAPHQL_COMMON_VER"

    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")

    testCompile("org.springframework.boot:spring-boot-starter-test")
}

jar.enabled = true
uploadArchives.enabled = false
bintrayUpload.enabled = false

After running gradle build, I run the generated jar file from the terminal. This is what I get on localhost:

enter image description here

Sobriety answered 5/8, 2017 at 14:1 Comment(1)
It's a little hard to tell what's going on without the full code, would you mind creating a sample project and throwing it up on github?Darter
O
3

I had the same issue using Spring boot 2.0.0 (M6). Switching back to 1.5.8.RELEASE solved the problem. They're working on the issue, it will be released as soon as there is a non milestone release for Spring boot 2.x

https://github.com/graphql-java/graphql-spring-boot/issues/40

https://github.com/graphql-java/graphql-spring-boot/pull/36

Odor answered 17/11, 2017 at 11:29 Comment(0)
S
0

Change to version 1.5.9.RELEASE of the spring-boot-starter-stop and it worked for me

Shogun answered 1/1, 2019 at 17:53 Comment(0)
J
0

I had a similar issue with a very simple GraphQL application that I had made based on an article, when I tested the http://localhost:8989/graphql with Postman I got 404 NOT_FOUND error, in my case the problem was that I was testing the API with a REST POST request call in the Postman, you need to create a new GraphQL request by clicking on New button in Postman and then if your application has been launched, automatically accessible API's is displayed, in my case the problem was that.

see the below screenshot: enter image description here

Jeromyjerreed answered 5/2 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.