7

我最近开始使用graphql它,发现它非常有趣。由于我的大多数rest应用程序都在 中java,我决定使用团队提供的spring boot 启动器项目进行快速设置。graphql-java它带有graph-iqlautoconf spring 设置,可以更轻松地查询/graphql端点。

在 IDEA 中的项目设置上花了几个小时后,我能够运行graphql-sample-app。但我认为我的 servlet 仍未启用,只有graphiql端点正在运行,因为默认查询正在返回404

这是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

这是我的build.gradle文件的样子:

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

运行后gradle build,我jar从终端运行生成的文件。这是我在本地主机上得到的:

在此处输入图像描述

4

2 回答 2

2

我在使用 Spring boot 2.0.0 (M6) 时遇到了同样的问题。切换回 1.5.8.RELEASE 解决了这个问题。他们正在解决这个问题,一旦有 Spring boot 2.x 的非里程碑版本,它将立即发布

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

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

于 2017-11-17T11:29:11.157 回答
0

更改为 spring-boot-starter-stop 的 1.5.9.RELEASE 版本,它对我有用

于 2019-01-01T17:53:51.730 回答