javaspringspring-bootgraphqlgraphql-java

spring boot starter graphql not working


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


Solution

  • 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