commit
3f33e636f1
9 changed files with 134 additions and 1 deletions
1
graphql-server/.gitignore
vendored
Normal file
1
graphql-server/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build
|
41
graphql-server/build.gradle.kts
Normal file
41
graphql-server/build.gradle.kts
Normal file
|
@ -0,0 +1,41 @@
|
|||
plugins {
|
||||
id("kotlin-platform-jvm")
|
||||
id("org.jetbrains.kotlin.plugin.spring") version("1.6.10")
|
||||
id("org.jetbrains.kotlin.plugin.serialization")
|
||||
id("org.springframework.boot") version("2.5.6")
|
||||
id("com.google.cloud.tools.appengine") version("2.4.2")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation("com.expediagroup:graphql-kotlin-spring-server:5.3.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
|
||||
|
||||
testImplementation("com.squareup.okhttp3:okhttp:4.9.3")
|
||||
|
||||
with(Deps.Log) {
|
||||
implementation(logback)
|
||||
}
|
||||
|
||||
implementation(project(":common"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets.all {
|
||||
languageSettings {
|
||||
optIn("kotlin.RequiresOptIn")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appengine {
|
||||
stage {
|
||||
setArtifact(tasks.named("bootJar").flatMap { (it as Jar).archiveFile })
|
||||
}
|
||||
deploy {
|
||||
projectId = "peopleinspace-graphql"
|
||||
version = "GCLOUD_CONFIG"
|
||||
}
|
||||
}
|
3
graphql-server/src/main/appengine/app.yaml
Normal file
3
graphql-server/src/main/appengine/app.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
runtime: java11
|
||||
|
||||
entrypoint: java -Xmx64m -jar graphql-server.jar
|
|
@ -0,0 +1,20 @@
|
|||
package com.surrus.peopleinspace
|
||||
|
||||
import com.surrus.common.di.initKoin
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
|
||||
|
||||
val koin = initKoin(enableNetworkLogs = true).koin
|
||||
|
||||
@SpringBootApplication
|
||||
class DefaultApplication {
|
||||
}
|
||||
|
||||
fun runServer(): ConfigurableApplicationContext {
|
||||
return runApplication<DefaultApplication>()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.surrus.peopleinspace
|
||||
|
||||
import com.expediagroup.graphql.server.operations.Subscription
|
||||
import com.surrus.common.remote.IssPosition
|
||||
import com.surrus.common.remote.PeopleInSpaceApi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.reactive.asPublisher
|
||||
import org.reactivestreams.Publisher
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
class IssPositionSubscription : Subscription {
|
||||
private val logger: Logger = LoggerFactory.getLogger(IssPositionSubscription::class.java)
|
||||
private var peopleInSpaceApi: PeopleInSpaceApi = koin.get()
|
||||
|
||||
|
||||
fun issPosition(): Publisher<IssPosition> {
|
||||
return flow {
|
||||
while (true) {
|
||||
val position = peopleInSpaceApi.fetchISSPosition().iss_position
|
||||
logger.info("ISS position = $position")
|
||||
emit(position)
|
||||
delay(POLL_INTERVAL)
|
||||
}
|
||||
}.asPublisher()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val POLL_INTERVAL = 10000L
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.surrus.peopleinspace
|
||||
|
||||
import com.expediagroup.graphql.server.operations.Query
|
||||
import com.surrus.common.remote.PeopleInSpaceApi
|
||||
import com.surrus.common.remote.Assignment
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
data class People(val people: List<Assignment>)
|
||||
|
||||
@Component
|
||||
class RootQuery : Query {
|
||||
private var peopleInSpaceApi: PeopleInSpaceApi = koin.get()
|
||||
|
||||
suspend fun allPeople(): People = People(peopleInSpaceApi.fetchPeople().people)
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.surrus.peopleinspace
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runServer()
|
||||
}
|
||||
|
2
graphql-server/src/main/resources/application.yml
Normal file
2
graphql-server/src/main/resources/application.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
graphql:
|
||||
packages: "com.surrus"
|
|
@ -4,12 +4,20 @@ pluginManagement {
|
|||
mavenCentral()
|
||||
maven(url = "https://maven.pkg.jetbrains.space/public/p/compose/dev")
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id.startsWith("com.google.cloud.tools.appengine")) {
|
||||
useModule("com.google.cloud.tools:appengine-gradle-plugin:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "PeopleInSpace"
|
||||
|
||||
include(":app", ":common", ":compose-desktop")
|
||||
include(":wearApp")
|
||||
include(":web")
|
||||
include(":compose-web")
|
||||
include(":backend")
|
||||
include(":wearApp")
|
||||
include(":graphql-server")
|
||||
|
|
Loading…
Reference in a new issue