Skip to content

Commit

Permalink
Revert "feat(generator): avoid adding input-suffix for input-only c…
Browse files Browse the repository at this point in the history
…lasses (#1434)" (#1438)

This reverts commit 0cca1e4.
  • Loading branch information
samuelAndalon authored May 6, 2022
1 parent 8da7aed commit 053bce0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.expediagroup.graphql.generator.internal.extensions

import com.expediagroup.graphql.generator.annotations.GraphQLValidObjectLocations
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
import com.expediagroup.graphql.generator.internal.filters.functionFilters
Expand All @@ -29,7 +28,6 @@ import kotlin.reflect.KProperty
import kotlin.reflect.KVisibility
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.findParameterByName
import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.full.memberFunctions
Expand Down Expand Up @@ -91,22 +89,11 @@ internal fun KClass<*>.getSimpleName(isInputClass: Boolean = false): String {
?: throw CouldNotGetNameOfKClassException(this)

return when {
isInputClass -> {
if (name.endsWith(INPUT_SUFFIX, true) || this.isInputOnlyLocationRestricted()) {
name
} else {
"$name$INPUT_SUFFIX"
}
}
isInputClass -> if (name.endsWith(INPUT_SUFFIX, true)) name else "$name$INPUT_SUFFIX"
else -> name
}
}

private fun KClass<*>.isInputOnlyLocationRestricted(): Boolean = findAnnotation<GraphQLValidObjectLocations>()
?.locations
?.all { it == GraphQLValidObjectLocations.Locations.INPUT_OBJECT }
?: false

internal fun KClass<*>.getQualifiedName(): String = this.qualifiedName.orEmpty()

internal fun KClass<*>.isPublic(): Boolean = this.visibility == KVisibility.PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class GenerateInputObjectTest : TypeTestHelper() {
val myField: String = "car"
}

@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
class InputAndObjectLocation {
val myField: String = "car"
}

@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT])
class OutputOnly {
val myField: String = "car"
Expand Down Expand Up @@ -110,18 +105,6 @@ class GenerateInputObjectTest : TypeTestHelper() {
}
}

@Test
fun `input only objects are not suffixed with 'Input'`() {
val result = generateInputObject(generator, InputOnly::class)
assertEquals("InputOnly", result.name)
}

@Test
fun `input and object located objects are suffixed with 'Input'`() {
val result = generateInputObject(generator, InputAndObjectLocation::class)
assertEquals("InputAndObjectLocationInput", result.name)
}

@Test
fun `output only objects throw an exception`() {
assertFailsWith(InvalidObjectLocationException::class) {
Expand Down
3 changes: 1 addition & 2 deletions website/docs/schema-generator/writing-schemas/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ This behavior is true for all arguments except for the special classes for the [
Query, Mutation, and Subscription function arguments are automatically converted to GraphQL input fields. GraphQL makes a
distinction between input and output types and requires unique names for all the types. Since we can use the same
objects for input and output in our Kotlin functions, `graphql-kotlin-schema-generator` will automatically append
an `Input` suffix to the GraphQL name of input objects, unless the type is [restricted to being used for
input only](../customizing-schemas/restricting-input-output.md).
an `Input` suffix to the GraphQL name of input objects.

For example, the following code:

Expand Down

0 comments on commit 053bce0

Please sign in to comment.