
SpringBoot + Kotlin + GraphQL에 잡입문
기사로서는 꽤 거칠다.
서버측 Kotlin에 입문하기 위해 공부 기사가 됩니다.
그건 그렇고, 우리는 안드로이드 엔지니어에서 서버 측 경험이 0입니다.
SpringBoot
Kotlin
GraphQL
IntelliJ IDEA 2019.1 (Ultimate Edition)
JRE: 1.8.0_202-release-1483-b39 x86_64
macOS 10.14.4
Graphql 요청에
우선 프로젝트 작성
프로젝트 이름은 kotlin-graphql-sample이었습니다.
build.gradle을 다음과 같이 수정
커밋
htps : // 기주 b. 코 m / 이케 무라 23 / 코 t ぃ - g et al phql - mp
build.gradle
빌드 로그에 오류가 없으면 OK
scheme이라고 하는지 모르지만, query 파일을 작성한다
query.graphqls
version이라는 요청에 대해 String 형을 반환한다는 의미입니다.
String!의
graphql의 요청에 대해 Kotlin의 처리를 설명합니다.
Query.kt
이 시점에서
오류가 없으면 다음 spring-boot-devtools에 액세스 할 수 있습니다.
사용법은 다음과 같습니다.
왼쪽에 쿼리 작성 ▶ 버튼으로 요청 오른쪽에 응답이 표시됩니다

이제 간단한 SpringBoot + Kotlin + GraphQL을 만들 수있었습니다.
사실은 여러가지 시도했지만, 이번은 여기까지.
GitHub에 코드가 모두 실려 있기 때문에보고 싶다면 부디
서버측 Kotlin에 입문하기 위해 공부 기사가 됩니다.
그건 그렇고, 우리는 안드로이드 엔지니어에서 서버 측 경험이 0입니다.
사용하는 것
SpringBoot
Kotlin
GraphQL
환경
IntelliJ IDEA 2019.1 (Ultimate Edition)
JRE: 1.8.0_202-release-1483-b39 x86_64
macOS 10.14.4
구현 1 우선 간단하게
Graphql 요청에
version
가 있으면 항상 1.0
를 반환하는 프로세스를 만듭니다.우선 프로젝트 작성
프로젝트 이름은 kotlin-graphql-sample이었습니다.
graphql 라이브러리 추가
build.gradle을 다음과 같이 수정
커밋
htps : // 기주 b. 코 m / 이케 무라 23 / 코 t ぃ - g et al phql - mp
build.gradle
// buildscriptを追加
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE"
}
}
// apply pluginを追加
apply plugin: 'kotlin'
apply plugin: "kotlin-spring"
apply plugin: 'kotlin-kapt'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'kotlin'
version '1.0-SNAPSHOT'
repositories {
jcenter() // 追加
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// ここから追加
compile 'com.graphql-java-kickstart:graphql-spring-boot-starter:5.7.3'
// to embed Altair tool
runtime 'com.graphql-java-kickstart:altair-spring-boot-starter:5.7.3'
// to embed GraphiQL tool
runtime 'com.graphql-java-kickstart:graphiql-spring-boot-starter:5.7.3'
// to embed Voyager tool
runtime 'com.graphql-java-kickstart:voyager-spring-boot-starter:5.7.3'
implementation 'org.springframework.boot:spring-boot-devtools'
// testing facilities
testCompile 'com.graphql-java-kickstart:graphql-spring-boot-starter-test:5.7.3'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
MainApplication 클래스 만들기
package demo
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication //アノテーション追加
class MainApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(MainApplication::class.java, *args)
}
}
}
MainApplication
를 시도해보십시오.빌드 로그에 오류가 없으면 OK
graphql scheme 만들기
scheme이라고 하는지 모르지만, query 파일을 작성한다
query.graphqls
type Query {
version: String!
}
version이라는 요청에 대해 String 형을 반환한다는 의미입니다.
String!의
!
는 "Null이 아니다"라는 것 같습니다graphql의 Kotlin 코드 작성
graphql의 요청에 대해 Kotlin의 처리를 설명합니다.
Query.kt
@Component
class Query : GraphQLQueryResolver {
// versionというリクエストに対して
fun version(): String {
return "1.0" // 常に1.0を返す
}
}
이 시점에서
MainApplication
를 다시 빌드하고 실행합니다.오류가 없으면 다음 spring-boot-devtools에 액세스 할 수 있습니다.
사용법은 다음과 같습니다.

이제 간단한 SpringBoot + Kotlin + GraphQL을 만들 수있었습니다.
완제품
사실은 여러가지 시도했지만, 이번은 여기까지.
GitHub에 코드가 모두 실려 있기 때문에보고 싶다면 부디