diff --git a/graphql-server/.gitignore b/graphql-server/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/graphql-server/.gitignore @@ -0,0 +1 @@ +build diff --git a/graphql-server/build.gradle.kts b/graphql-server/build.gradle.kts new file mode 100644 index 0000000..0377aa3 --- /dev/null +++ b/graphql-server/build.gradle.kts @@ -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" + } +} \ No newline at end of file diff --git a/graphql-server/src/main/appengine/app.yaml b/graphql-server/src/main/appengine/app.yaml new file mode 100644 index 0000000..b78d712 --- /dev/null +++ b/graphql-server/src/main/appengine/app.yaml @@ -0,0 +1,3 @@ +runtime: java11 + +entrypoint: java -Xmx64m -jar graphql-server.jar diff --git a/graphql-server/src/main/kotlin/com/surrus/peopleinspace/DefaultApplication.kt b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/DefaultApplication.kt new file mode 100644 index 0000000..0e0a8f4 --- /dev/null +++ b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/DefaultApplication.kt @@ -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() +} + + + diff --git a/graphql-server/src/main/kotlin/com/surrus/peopleinspace/IssPositionSubscription.kt b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/IssPositionSubscription.kt new file mode 100644 index 0000000..ac66044 --- /dev/null +++ b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/IssPositionSubscription.kt @@ -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 { + 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 + } + +} \ No newline at end of file diff --git a/graphql-server/src/main/kotlin/com/surrus/peopleinspace/graph.kt b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/graph.kt new file mode 100644 index 0000000..07563f4 --- /dev/null +++ b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/graph.kt @@ -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) + +@Component +class RootQuery : Query { + private var peopleInSpaceApi: PeopleInSpaceApi = koin.get() + + suspend fun allPeople(): People = People(peopleInSpaceApi.fetchPeople().people) +} diff --git a/graphql-server/src/main/kotlin/com/surrus/peopleinspace/main.kt b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/main.kt new file mode 100644 index 0000000..c5d8590 --- /dev/null +++ b/graphql-server/src/main/kotlin/com/surrus/peopleinspace/main.kt @@ -0,0 +1,6 @@ +package com.surrus.peopleinspace + +fun main(args: Array) { + runServer() +} + diff --git a/graphql-server/src/main/resources/application.yml b/graphql-server/src/main/resources/application.yml new file mode 100644 index 0000000..736180a --- /dev/null +++ b/graphql-server/src/main/resources/application.yml @@ -0,0 +1,2 @@ +graphql: + packages: "com.surrus" diff --git a/settings.gradle.kts b/settings.gradle.kts index 2734517..3a35e31 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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")