我最近开始使用graphql
它,发现它非常有趣。由于我的大多数rest
应用程序都在 中java
,我决定使用团队提供的spring boot 启动器项目进行快速设置。graphql-java
它带有graph-iql
autoconf 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
从终端运行生成的文件。这是我在本地主机上得到的: