Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = disabled
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Ignore Gradle project-specific cache directory
.gradle
.fleet

# Ignore Gradle build output directory
build

.idea/
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 28 additions & 27 deletions base/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,43 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
aopalliance:aopalliance:1.0=compileClasspath,runtimeClasspath
ch.qos.logback:logback-classic:1.2.3=compileClasspath,runtimeClasspath
ch.qos.logback:logback-core:1.2.3=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.14.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.14.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.14.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.14.2=compileClasspath,runtimeClasspath
ch.qos.logback:logback-classic:1.4.11=compileClasspath,runtimeClasspath
ch.qos.logback:logback-core:1.4.11=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=compileClasspath,runtimeClasspath
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,runtimeClasspath
com.google.code.gson:gson:2.8.6=compileClasspath,runtimeClasspath
com.google.errorprone:error_prone_annotations:2.3.4=compileClasspath,runtimeClasspath
com.google.code.gson:gson:2.10=compileClasspath,runtimeClasspath
com.google.errorprone:error_prone_annotations:2.7.1=compileClasspath,runtimeClasspath
com.google.guava:failureaccess:1.0.1=compileClasspath,runtimeClasspath
com.google.guava:guava:30.1-jre=compileClasspath,runtimeClasspath
com.google.guava:guava:31.0.1-jre=compileClasspath,runtimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=compileClasspath,runtimeClasspath
com.google.inject:guice:5.1.0=compileClasspath,runtimeClasspath
com.google.inject:guice:7.0.0=compileClasspath,runtimeClasspath
com.google.j2objc:j2objc-annotations:1.3=compileClasspath,runtimeClasspath
com.konghq:unirest-java:3.11.09=compileClasspath,runtimeClasspath
commons-codec:commons-codec:1.11=compileClasspath,runtimeClasspath
com.konghq:unirest-java:3.14.5=compileClasspath,runtimeClasspath
commons-codec:commons-codec:1.15=compileClasspath,runtimeClasspath
commons-logging:commons-logging:1.2=compileClasspath,runtimeClasspath
dev.misfitlabs.kotlinguice4:kotlin-guice:1.6.0=compileClasspath,runtimeClasspath
info.offthecob.platform:bom:1.0.11=compileClasspath,runtimeClasspath
info.offthecob.platform:common:1.0.11=compileClasspath,runtimeClasspath
io.github.microutils:kotlin-logging:1.7.6=compileClasspath,runtimeClasspath
javax.inject:javax.inject:1=compileClasspath,runtimeClasspath
net.logstash.logback:logstash-logback-encoder:7.3=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpasyncclient:4.1.4=compileClasspath,runtimeClasspath
dev.misfitlabs.kotlinguice4:kotlin-guice:3.0.0=compileClasspath,runtimeClasspath
info.offthecob.platform:bom:1.0.15=compileClasspath,runtimeClasspath
info.offthecob.platform:common:1.0.15=compileClasspath,runtimeClasspath
io.github.microutils:kotlin-logging-jvm:3.0.5=compileClasspath,runtimeClasspath
io.github.microutils:kotlin-logging:3.0.5=compileClasspath,runtimeClasspath
jakarta.inject:jakarta.inject-api:2.0.1=compileClasspath,runtimeClasspath
net.logstash.logback:logstash-logback-encoder:7.4=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpasyncclient:4.1.5=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpclient:4.5.13=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpcore-nio:4.4.13=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpcore:4.4.13=compileClasspath,runtimeClasspath
org.apache.httpcomponents:httpmime:4.5.13=compileClasspath,runtimeClasspath
org.checkerframework:checker-qual:3.5.0=compileClasspath,runtimeClasspath
org.checkerframework:checker-qual:3.12.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-reflect:1.4.32=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.9.0=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,runtimeClasspath
org.slf4j:jcl-over-slf4j:1.7.25=compileClasspath,runtimeClasspath
org.slf4j:jul-to-slf4j:1.7.25=compileClasspath,runtimeClasspath
org.slf4j:slf4j-api:1.7.25=compileClasspath,runtimeClasspath
org.slf4j:jcl-over-slf4j:2.0.9=compileClasspath,runtimeClasspath
org.slf4j:jul-to-slf4j:2.0.9=compileClasspath,runtimeClasspath
org.slf4j:slf4j-api:2.0.9=compileClasspath,runtimeClasspath
empty=annotationProcessor
4 changes: 2 additions & 2 deletions base/src/main/kotlin/BaseModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import com.google.inject.AbstractModule
import com.google.inject.Provides
import com.google.inject.Singleton
import com.google.inject.name.Named
import dev.misfitlabs.kotlinguice4.KotlinModule

const val WORD_URL = "word-url"
const val MIT_ECPRICE_WORD_LIST = "https://www.mit.edu/~ecprice/wordlist.10000"
const val NUMBER_OF_WORDS = "number-of-words"

class BaseModule : KotlinModule() {
class BaseModule : AbstractModule() {
@Provides
@Singleton
@Named(WORD_URL)
Expand Down
19 changes: 19 additions & 0 deletions library/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.fasterxml.jackson.core:jackson-annotations:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=compileClasspath,runtimeClasspath
com.graphql-java:graphql-java:19.2=compileClasspath,runtimeClasspath
com.graphql-java:java-dataloader:3.2.0=compileClasspath,runtimeClasspath
com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.5.1=compileClasspath,runtimeClasspath
com.netflix.graphql.dgs:graphql-dgs-platform:5.5.1=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-reflect:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,runtimeClasspath
org.reactivestreams:reactive-streams:1.0.3=compileClasspath,runtimeClasspath
org.slf4j:slf4j-api:1.7.30=compileClasspath
org.slf4j:slf4j-api:1.7.35=runtimeClasspath
empty=annotationProcessor
22 changes: 22 additions & 0 deletions library/library.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import com.netflix.graphql.dgs.codegen.gradle.GenerateJavaTask

plugins {
id("info.offthecob.Library")
id("com.netflix.dgs.codegen") version "6.0.2"
}

dependencies {
api("com.fasterxml.jackson.core:jackson-annotations:2.15.2")
}

tasks {
generateJava {
schemaPaths = mutableListOf("$projectDir/src/main/resources")
packageName = "info.offthecob.examples.library"
generateClient = false
language = "kotlin"
}
build {
dependsOn("generateJava")
}
}
13 changes: 13 additions & 0 deletions library/src/main/resources/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Word {
characters: String
weight: Int
color: String
}

input WordsInput {
numberOfWords: Int
}

type Query {
words(input: WordsInput!): [Word]
}
68 changes: 68 additions & 0 deletions service/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
aopalliance:aopalliance:1.0=compileClasspath,runtimeClasspath
ch.qos.logback:logback-classic:1.4.11=compileClasspath,runtimeClasspath
ch.qos.logback:logback-core:1.4.11=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.15.2=compileClasspath,runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=compileClasspath,runtimeClasspath
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,runtimeClasspath
com.google.code.gson:gson:2.10.1=compileClasspath,runtimeClasspath
com.google.errorprone:error_prone_annotations:2.7.1=compileClasspath,runtimeClasspath
com.google.guava:failureaccess:1.0.1=compileClasspath,runtimeClasspath
com.google.guava:guava:31.0.1-jre=compileClasspath,runtimeClasspath
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=compileClasspath,runtimeClasspath
com.google.inject:guice:7.0.0=compileClasspath,runtimeClasspath
com.google.j2objc:j2objc-annotations:1.3=compileClasspath,runtimeClasspath
com.graphql-java:graphql-java:19.2=compileClasspath,runtimeClasspath
com.graphql-java:java-dataloader:3.2.0=compileClasspath,runtimeClasspath
com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-shared-core:6.0.2=runtimeClasspath
com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.5.1=runtimeClasspath
com.netflix.graphql.dgs:graphql-dgs-platform:5.5.1=runtimeClasspath
commons-io:commons-io:2.13.0=compileClasspath,runtimeClasspath
dev.misfitlabs.kotlinguice4:kotlin-guice:3.0.0=compileClasspath,runtimeClasspath
info.offthecob.platform:bom:1.0.15=compileClasspath,runtimeClasspath
info.offthecob.platform:common:1.0.15=compileClasspath,runtimeClasspath
io.github.microutils:kotlin-logging-jvm:3.0.5=compileClasspath,runtimeClasspath
io.github.microutils:kotlin-logging:3.0.5=compileClasspath,runtimeClasspath
io.javalin:javalin:5.6.1=compileClasspath,runtimeClasspath
jakarta.annotation:jakarta.annotation-api:2.1.1=compileClasspath,runtimeClasspath
jakarta.inject:jakarta.inject-api:2.0.1=compileClasspath,runtimeClasspath
jakarta.transaction:jakarta.transaction-api:2.0.0=compileClasspath,runtimeClasspath
net.logstash.logback:logstash-logback-encoder:7.4=compileClasspath,runtimeClasspath
org.checkerframework:checker-qual:3.12.0=compileClasspath,runtimeClasspath
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-core-common:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-core-server:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-jetty-api:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-jetty-common:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-jetty-server:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty.websocket:websocket-servlet:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-annotations:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-http:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-io:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-jndi:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-plus:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-security:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-server:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-servlet:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-util:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-webapp:11.0.15=compileClasspath,runtimeClasspath
org.eclipse.jetty:jetty-xml:11.0.15=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-reflect:1.4.32=compileClasspath
org.jetbrains.kotlin:kotlin-reflect:1.9.0=runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.9.10=compileClasspath,runtimeClasspath
org.jetbrains:annotations:24.0.1=compileClasspath,runtimeClasspath
org.ow2.asm:asm-commons:9.5=compileClasspath,runtimeClasspath
org.ow2.asm:asm-tree:9.5=compileClasspath,runtimeClasspath
org.ow2.asm:asm:9.5=compileClasspath,runtimeClasspath
org.reactivestreams:reactive-streams:1.0.3=compileClasspath,runtimeClasspath
org.slf4j:jcl-over-slf4j:2.0.9=compileClasspath,runtimeClasspath
org.slf4j:jul-to-slf4j:2.0.9=compileClasspath,runtimeClasspath
org.slf4j:slf4j-api:2.0.9=compileClasspath,runtimeClasspath
empty=annotationProcessor
18 changes: 18 additions & 0 deletions service/service.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("info.offthecob.Service")
}

dependencies {
implementation(project(":library"))
implementation(platform(libs.offthecob.platform))
implementation("info.offthecob.platform:common")
implementation(libs.bundles.guice)
implementation(libs.bundles.logging)
implementation(libs.javalin)
implementation(libs.gson)
implementation(libs.graphql)
implementation(libs.commons.io)

testImplementation(libs.bundles.groovy)
testImplementation(libs.bundles.spock)
}
11 changes: 11 additions & 0 deletions service/src/main/kotlin/DataFetchers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import graphql.schema.DataFetcher
import info.offthecob.examples.library.types.Word

class DataFetchers {
fun getWords(): DataFetcher<List<Word>> {
return DataFetcher<List<Word>> { input ->
input.variables["numberOfWords"]
listOf(Word("dude", 1, "FFFFFF"))
}
}
}
65 changes: 65 additions & 0 deletions service/src/main/kotlin/GraphQLHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import com.google.gson.Gson
import com.google.inject.Inject
import graphql.ExecutionInput
import graphql.ExecutionResult
import graphql.GraphQL
import io.javalin.http.Context
import io.javalin.http.Handler

data class GraphqlRequest(
val query: String,
val variables: Map<String, Any>?,
val operationName: String?,
)

class GraphQLHandler @Inject constructor(
private val graphql: GraphQL,
private val gson: Gson,
) : Handler {
override fun handle(ctx: Context) {
if (ctx.body().isEmpty()) {
ctx.status(400)
ctx.result("Bad Request")
} else {
handleGraphqlRequest(ctx)
}
}

private fun handleGraphqlRequest(ctx: Context) {
val graphqlRequest = gson.fromJson(ctx.body(), GraphqlRequest::class.java)
val executionInput = executionInput(graphqlRequest, ctx)
val executionResult = graphql.execute(executionInput)
handleGraphqlExecutionResult(executionResult, ctx)
}

private fun handleGraphqlExecutionResult(executionResult: ExecutionResult, ctx: Context) {
if (executionResult.isDataPresent) {
ctx.result(gson.toJson(executionResult.toSpecification()))
ctx.status(200)
} else {
ctx.result("Bad Request")
ctx.status(400)
}
}

private fun executionInput(graphqlRequest: GraphqlRequest, ctx: Context): ExecutionInput {
val executionInputBuilder = ExecutionInput
.newExecutionInput(graphqlRequest.query)
.context(ctx)
variables(graphqlRequest, executionInputBuilder)
operationName(graphqlRequest, executionInputBuilder)
return executionInputBuilder.build()
}

private fun operationName(graphqlRequest: GraphqlRequest, executionInputBuilder: ExecutionInput.Builder) {
if (graphqlRequest.operationName?.isNotEmpty() == true) {
executionInputBuilder.operationName(graphqlRequest.operationName)
}
}

private fun variables(graphqlRequest: GraphqlRequest, executionInputBuilder: ExecutionInput.Builder) {
if (graphqlRequest.variables?.isNotEmpty() == true) {
executionInputBuilder.variables(graphqlRequest.variables)
}
}
}
24 changes: 24 additions & 0 deletions service/src/main/kotlin/ServiceMain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.google.inject.Guice
import com.google.inject.Inject
import dev.misfitlabs.kotlinguice4.getInstance
import io.javalin.Javalin

fun main() {
Guice
.createInjector(ServiceModule())
.getInstance<ServiceMain>()
.apply {
go()
}
}

class ServiceMain @Inject constructor(
private val javalin: Javalin,
private val graphQLHandler: GraphQLHandler,
) {
fun go() {
javalin
.post("/graphql", graphQLHandler)
.start()
}
}
Loading