diff --git a/build.gradle.kts b/build.gradle.kts index 965f79b6..f52cb641 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 } @@ -21,33 +16,10 @@ allprojects { subprojects { group = "com.apurebase" version = version - - apply() - - 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()) - } } diff --git a/kgraphql-example/build.gradle.kts b/kgraphql-example/build.gradle.kts index 441cfeee..1e98f89b 100644 --- a/kgraphql-example/build.gradle.kts +++ b/kgraphql-example/build.gradle.kts @@ -62,51 +62,3 @@ val dokkaJar by tasks.creating(Jar::class) { classifier = "javadoc" from(tasks.dokkaHtml) } - -publishing { - publications { - create("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("jol@apurebase.com") - } - } - 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"]) -} diff --git a/kgraphql-ktor/build.gradle.kts b/kgraphql-ktor/build.gradle.kts index 5b15a615..11999547 100644 --- a/kgraphql-ktor/build.gradle.kts +++ b/kgraphql-ktor/build.gradle.kts @@ -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 @@ -66,51 +67,3 @@ val dokkaJar by tasks.creating(Jar::class) { classifier = "javadoc" from(tasks.dokkaHtml) } - -publishing { - publications { - create("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("jol@apurebase.com") - } - } - 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"]) -} diff --git a/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt b/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt index bc7d5d08..2ee4965d 100644 --- a/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt +++ b/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt @@ -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) { @@ -42,9 +43,8 @@ class GraphQL(val schema: Schema) { } - companion object Feature: ApplicationFeature { - override val key = AttributeKey("KGraphQL") + override val key = AttributeKey("KGraphQL-" + UUID.randomUUID()) override fun install(pipeline: Application, configure: Configuration.() -> Unit): GraphQL { val config = Configuration().apply(configure) @@ -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) @@ -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() diff --git a/kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt b/kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt index 6f4ac8d4..ee327d2b 100644 --- a/kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt +++ b/kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt @@ -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.* @@ -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 + } + } diff --git a/kgraphql/build.gradle.kts b/kgraphql/build.gradle.kts index e420407d..29b00852 100644 --- a/kgraphql/build.gradle.kts +++ b/kgraphql/build.gradle.kts @@ -3,6 +3,7 @@ plugins { base kotlin("jvm") version "1.5.10" id("org.jetbrains.dokka") version "1.4.32" + id("maven-publish") signing } @@ -74,52 +75,4 @@ val dokkaJar by tasks.creating(Jar::class) { group = JavaBasePlugin.DOCUMENTATION_GROUP classifier = "javadoc" from(tasks.dokkaHtml) -} - -publishing { - publications { - create("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("jol@apurebase.com") - } - } - 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"]) -} +} \ No newline at end of file diff --git a/kgraphql/src/main/kotlin/com/apurebase/kgraphql/GraphQLError.kt b/kgraphql/src/main/kotlin/com/apurebase/kgraphql/GraphQLError.kt index 45723413..ad24624d 100644 --- a/kgraphql/src/main/kotlin/com/apurebase/kgraphql/GraphQLError.kt +++ b/kgraphql/src/main/kotlin/com/apurebase/kgraphql/GraphQLError.kt @@ -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? = null ) : Exception(message) { constructor(message: String, node: ASTNode?) : this(message, nodes = node?.let(::listOf))