Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extensions-Field to GraphQLError.kt #166

Closed
wants to merge 13 commits into from
30 changes: 1 addition & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import de.marcphilipp.gradle.nexus.NexusPublishPlugin
import java.time.Duration

val version: String by project
val sonatypeUsername: String? = System.getenv("sonatypeUsername")
val sonatypePassword: String? = System.getenv("sonatypePassword")

plugins {
id("com.github.ben-manes.versions") version "0.39.0"
id("io.codearte.nexus-staging") version "0.30.0"
id("de.marcphilipp.nexus-publish") version "0.4.0"
id("maven-publish")
jacoco
}

Expand All @@ -21,33 +16,10 @@ allprojects {
subprojects {
group = "com.apurebase"
version = version

apply<NexusPublishPlugin>()

nexusPublishing {
repositories {
sonatype()
}
clientTimeout.set(Duration.parse("PT10M")) // 10 minutes
}
}

nexusStaging {
packageGroup = "com.apurebase"
username = sonatypeUsername
password = sonatypePassword
numberOfRetries = 360 // 1 hour if 10 seconds delay
delayBetweenRetriesInMillis = 10000 // 10 seconds
}

tasks {
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
closeRepository {
mustRunAfter(subprojects.map { it.tasks.getByName("publishToSonatype") }.toTypedArray())
}
closeAndReleaseRepository {
mustRunAfter(subprojects.map { it.tasks.getByName("publishToSonatype") }.toTypedArray())
}
}
48 changes: 0 additions & 48 deletions kgraphql-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,51 +62,3 @@ val dokkaJar by tasks.creating(Jar::class) {
classifier = "javadoc"
from(tasks.dokkaHtml)
}

publishing {
publications {
create<MavenPublication>("maven") {
artifactId = project.name
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
pom {
name.set("KGraphQL")
description.set("KGraphQL is a Kotlin implementation of GraphQL. It provides a rich DSL to set up the GraphQL schema.")
url.set("https://kgraphql.io/")
organization {
name.set("aPureBase")
url.set("http://apurebase.com/")
}
licenses {
license {
name.set("MIT License")
url.set("https://github.com/aPureBase/KGraphQL/blob/main/LICENSE.md")
}
}
developers {
developer {
id.set("jeggy")
name.set("Jógvan Olsen")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
developerConnection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
url.set("https://github.com/aPureBase/KGraphQL/")
tag.set("HEAD")
}
}
}
}
}

signing {
isRequired = isReleaseVersion
useInMemoryPgpKeys(
System.getenv("ORG_GRADLE_PROJECT_signingKey"),
System.getenv("ORG_GRADLE_PROJECT_signingPassword")
)
sign(publishing.publications["maven"])
}
49 changes: 1 addition & 48 deletions kgraphql-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
kotlin("plugin.serialization") version "1.5.0"
id("org.jetbrains.dokka") version "1.4.32"
signing
id("maven-publish")
}

val caffeine_version: String by project
Expand Down Expand Up @@ -66,51 +67,3 @@ val dokkaJar by tasks.creating(Jar::class) {
classifier = "javadoc"
from(tasks.dokkaHtml)
}

publishing {
publications {
create<MavenPublication>("maven") {
artifactId = project.name
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
pom {
name.set("KGraphQL")
description.set("KGraphQL is a Kotlin implementation of GraphQL. It provides a rich DSL to set up the GraphQL schema.")
url.set("https://kgraphql.io/")
organization {
name.set("aPureBase")
url.set("http://apurebase.com/")
}
licenses {
license {
name.set("MIT License")
url.set("https://github.com/aPureBase/KGraphQL/blob/main/LICENSE.md")
}
}
developers {
developer {
id.set("jeggy")
name.set("Jógvan Olsen")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
developerConnection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
url.set("https://github.com/aPureBase/KGraphQL/")
tag.set("HEAD")
}
}
}
}
}

signing {
isRequired = isReleaseVersion
useInMemoryPgpKeys(
System.getenv("ORG_GRADLE_PROJECT_signingKey"),
System.getenv("ORG_GRADLE_PROJECT_signingPassword")
)
sign(publishing.publications["maven"])
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.nio.charset.Charset
import kotlinx.coroutines.coroutineScope
import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json.Default.decodeFromString
import java.util.*

class GraphQL(val schema: Schema) {

Expand Down Expand Up @@ -42,9 +43,8 @@ class GraphQL(val schema: Schema) {

}


companion object Feature: ApplicationFeature<Application, Configuration, GraphQL> {
override val key = AttributeKey<GraphQL>("KGraphQL")
override val key = AttributeKey<GraphQL>("KGraphQL-" + UUID.randomUUID())

override fun install(pipeline: Application, configure: Configuration.() -> Unit): GraphQL {
val config = Configuration().apply(configure)
Expand Down Expand Up @@ -103,7 +103,7 @@ class GraphQL(val schema: Schema) {
return receiveStream().bufferedReader(charset = suitableCharset).readText()
}

private fun GraphQLError.serialize(): String = buildJsonObject {
internal fun GraphQLError.serialize(): String = buildJsonObject {
put("errors", buildJsonArray {
addJsonObject {
put("message", message)
Expand All @@ -118,6 +118,13 @@ class GraphQL(val schema: Schema) {
put("path", buildJsonArray {
// TODO: Build this path. https://spec.graphql.org/June2018/#example-90475
})
extensions?.let {
put("extensions", buildJsonObject {
it.forEach { (key, value) ->
put(key, value)
}
})
}
}
})
}.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.apurebase.kgraphql

import com.apurebase.kgraphql.GraphQL.Feature.serialize
import io.ktor.application.*
import io.ktor.auth.*
import kotlinx.serialization.json.*
Expand Down Expand Up @@ -110,4 +111,30 @@ class KtorFeatureTest : KtorTest() {
}
} shouldBeEqualTo "{\"data\":{\"test\":\"success: InputTwo(one=InputOne(enum=M1, id=M1), quantity=3434, tokens=[23, 34, 21, 434])\"}}"
}

@Test
fun `Error serializer test`() {
val graphqlError = GraphQLError(
message = "test",
extensions = mapOf(
"code" to "BAD_USER_INPUT"
)
)

val expectedJson = buildJsonObject {
put("errors", buildJsonArray {
addJsonObject {
put("message", "test")
put("locations", buildJsonArray {})
put("path", buildJsonArray {})
put("extensions", buildJsonObject {
put("code", "BAD_USER_INPUT")
})
}
})
}.toString()

graphqlError.serialize() shouldBeEqualTo expectedJson
}

}
51 changes: 2 additions & 49 deletions kgraphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
base
kotlin("jvm") version "1.5.10"
id("org.jetbrains.dokka") version "1.4.32"
id("maven-publish")
signing
}

Expand Down Expand Up @@ -74,52 +75,4 @@ val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
classifier = "javadoc"
from(tasks.dokkaHtml)
}

publishing {
publications {
create<MavenPublication>("maven") {
artifactId = project.name
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
pom {
name.set("KGraphQL")
description.set("KGraphQL is a Kotlin implementation of GraphQL. It provides a rich DSL to set up the GraphQL schema.")
url.set("https://kgraphql.io/")
organization {
name.set("aPureBase")
url.set("http://apurebase.com/")
}
licenses {
license {
name.set("MIT License")
url.set("https://github.com/aPureBase/KGraphQL/blob/main/LICENSE.md")
}
}
developers {
developer {
id.set("jeggy")
name.set("Jógvan Olsen")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
developerConnection.set("scm:git:https://github.com/aPureBase/KGraphQL.git")
url.set("https://github.com/aPureBase/KGraphQL/")
tag.set("HEAD")
}
}
}
}
}

signing {
isRequired = isReleaseVersion
useInMemoryPgpKeys(
System.getenv("ORG_GRADLE_PROJECT_signingKey"),
System.getenv("ORG_GRADLE_PROJECT_signingPassword")
)
sign(publishing.publications["maven"])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ open class GraphQLError(
/**
* The original error thrown from a field resolver during execution.
*/
val originalError: Throwable? = null
val originalError: Throwable? = null,

/**
* Additional information to the error
*/
val extensions: Map<String, String>? = null
) : Exception(message) {

constructor(message: String, node: ASTNode?) : this(message, nodes = node?.let(::listOf))
Expand Down