Skip to content

Commit

Permalink
refactor: Cleanup code
Browse files Browse the repository at this point in the history
Mostly removes unused code and cleans up other minor stuff.
  • Loading branch information
stuebingerb committed Jan 8, 2025
1 parent c1498ac commit febebe6
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 29 deletions.
2 changes: 0 additions & 2 deletions kgraphql-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ plugins {
alias(libs.plugins.serialization)
}

val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")

dependencies {
api(project(":kgraphql"))
implementation(kotlin("stdlib-jdk8"))
Expand Down
2 changes: 0 additions & 2 deletions kgraphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ plugins {
id("library-conventions")
}

val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.apurebase.kgraphql.schema.dsl

import com.apurebase.kgraphql.configuration.PluginConfiguration
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.apurebase.kgraphql.configuration.SchemaConfiguration
import com.apurebase.kgraphql.schema.execution.Executor
import com.apurebase.kgraphql.schema.execution.GenericTypeResolver
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlin.reflect.KClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DataLoaderPreparedRequestExecutor(val schema: DefaultSchema) : RequestExec
this is Boolean -> JsonPrimitive(this)
this is Long -> JsonPrimitive(this)
returnType.unwrapped() is Type.Enum<*> -> JsonPrimitive(toString())
else -> error("Whaa? -> $this")
else -> error("Unexpected primitive class: $this")
}

private suspend fun <T> DeferredJsonMap.applyKeyToElement(
Expand Down Expand Up @@ -136,7 +136,7 @@ class DataLoaderPreparedRequestExecutor(val schema: DefaultSchema) : RequestExec
}
}
} else {
throw ExecutionException("Invalid collection value for non collection property", node)
throw ExecutionException("Invalid collection value for non-collection property", node)
}
}

Expand Down Expand Up @@ -400,7 +400,7 @@ class DataLoaderPreparedRequestExecutor(val schema: DefaultSchema) : RequestExec
if (returnType.kind != TypeKind.NON_NULL) {
JsonNull
} else {
throw ExecutionException("null result for non-nullable operation ${node.field}", node)
throw ExecutionException("null result for non-nullable operation ${node.field.name}", node)
}

private suspend fun shouldInclude(ctx: ExecutionContext, executionNode: Execution): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sealed class Execution {
val key: String,
val alias: String? = null,
val arguments: ArgumentNodes? = null,
val typeCondition: TypeCondition? = null,
override val directives: Map<Directive, ArgumentNodes?>? = null,
val variables: List<VariableDefinitionNode>? = null
) : Execution() {
Expand All @@ -39,16 +38,14 @@ sealed class Execution {
val unionField: Field.Union<*>,
val memberChildren: Map<__Type, Collection<Execution>>,
key: String,
alias: String? = null,
condition: TypeCondition? = null,
directives: Map<Directive, ArgumentNodes?>? = null
alias: String?,
directives: Map<Directive, ArgumentNodes?>?
) : Node(
selectionNode = node,
field = unionField,
children = emptyList(),
key = key,
alias = alias,
typeCondition = condition,
directives = directives
) {
fun memberExecution(type: __Type): Node {
Expand All @@ -61,7 +58,6 @@ sealed class Execution {
key = key,
alias = alias,
arguments = arguments,
typeCondition = typeCondition,
directives = directives,
variables = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ParallelRequestExecutor(val schema: DefaultSchema) : RequestExecutor {
array.add(valuesMap[v])
}
} else {
throw ExecutionException("Invalid collection value for non collection property", node)
throw ExecutionException("Invalid collection value for non-collection property", node)
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class ParallelRequestExecutor(val schema: DefaultSchema) : RequestExecutor {
if (returnType.kind != TypeKind.NON_NULL) {
return jsonNodeFactory.nullNode()
} else {
throw ExecutionException("null result for non-nullable operation ${node.field}", node)
throw ExecutionException("null result for non-nullable operation ${node.field.name}", node)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.apurebase.kgraphql.schema.model.ast
* Contains a range of UTF-8 character offsets and token references that
* identify the region of the source from which the AST derived.
*/
class Location(
data class Location(
/**
* The character offset at which this Node begins.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ sealed class ValueNode(override val loc: Location?) : ASTNode() {

val valueNodeName: String
get() = when (this) {
is VariableNode -> name.value
is VariableNode -> "\$${name.value}"
is NumberValueNode -> "$value"
is DoubleValueNode -> "$value"
is StringValueNode -> "\"$value\""
is BooleanValueNode -> "$value"
is NullValueNode -> "null"
is EnumValueNode -> value
is ListValueNode -> values.joinToString(prefix = "[", postfix = "]") { it.valueNodeName }
is ObjectValueNode -> fields.joinToString { "${it.name.value}: ${it.value.valueNodeName}" }
is ObjectValueNode -> fields.joinToString(prefix = "{", postfix = "}") { "${it.name.value}: ${it.value.valueNodeName}" }
is ObjectValueNode.ObjectFieldNode -> value.valueNodeName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ class RequestInterpreter(private val schemaModel: SchemaModel) {
memberChildren = unionMembersChildren,
key = selectionNode.name.value,
alias = selectionNode.alias?.value,
condition = null,
directives = selectionNode.directives?.lookup()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ abstract class BaseSchemaTest {
actor
}
}
mutation("createActorWithContext") {
description = "create new actor with context"
resolver { name: String, age: Int, ctx: Context ->
val actor = Actor(name, age)
createdActors.add(actor)
actor
}
}
mutation("createActorWithInput") {
description = "create new actor"
resolver { input: ActorInput ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ class MutationTest : BaseSchemaTest() {
}
}

@Test
fun `invalid arguments number with NotIntrospected class`() {
invoking {
execute("mutation {createActorWithContext(name: \"${testActor.name}\", age: ${testActor.age}, bananan: \"fwfwf\"){age}}")
} shouldThrow ValidationException::class with {
message shouldBeEqualTo "createActorWithContext does support arguments [name, age]. Found arguments [name, age, bananan]"
}
}

@Test
fun `mutation with alias`() {
val map = execute("mutation {caine : createActor(name: \"${testActor.name}\", age: ${testActor.age}){age}}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,25 @@ class SchemaPrinterTest {
@Test
fun `schema with input types should be printed as expected`() {
val schema = KGraphQL.schema {
inputType<TestObject> {
name = "TestObjectInput"
}
mutation("add") {
resolver { inputObject: InputObject -> inputObject.id }
resolver { input: TestObject -> input }
}
}

SchemaPrinter().print(schema) shouldBeEqualTo """
type Mutation {
add(inputObject: InputObject!): Int!
add(input: TestObjectInput!): TestObject!
}
input InputObject {
id: Int!
intInput: Int!
optional: String
stringInput: String!
type TestObject {
name: String!
}
input TestObjectInput {
name: String!
}
""".trimIndent()
Expand Down

0 comments on commit febebe6

Please sign in to comment.