【发布时间】:2018-01-13 08:00:33
【问题描述】:
我最近开始与graphql 合作,发现它非常有趣。由于我的大部分rest 应用程序都在java 中,我决定使用graphql-java 团队提供的spring boot starter 项目进行快速设置。它带有graph-iql autoconf spring setup,可以更轻松地查询/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 文件。这是我在本地主机上得到的:
【问题讨论】:
-
如果没有完整的代码,很难判断发生了什么,您介意创建一个示例项目并将其扔到 github 上吗?
标签: java spring spring-boot graphql graphql-java