Skip to content

Commit 053bce0

Browse files
Revert "feat(generator): avoid adding input-suffix for input-only classes (#1434)" (#1438)
This reverts commit 0cca1e4.
1 parent 8da7aed commit 053bce0

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

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

19-
import com.expediagroup.graphql.generator.annotations.GraphQLValidObjectLocations
2019
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
2120
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
2221
import com.expediagroup.graphql.generator.internal.filters.functionFilters
@@ -29,7 +28,6 @@ import kotlin.reflect.KProperty
2928
import kotlin.reflect.KVisibility
3029
import kotlin.reflect.full.declaredMemberFunctions
3130
import kotlin.reflect.full.declaredMemberProperties
32-
import kotlin.reflect.full.findAnnotation
3331
import kotlin.reflect.full.findParameterByName
3432
import kotlin.reflect.full.isSubclassOf
3533
import kotlin.reflect.full.memberFunctions
@@ -91,22 +89,11 @@ internal fun KClass<*>.getSimpleName(isInputClass: Boolean = false): String {
9189
?: throw CouldNotGetNameOfKClassException(this)
9290

9391
return when {
94-
isInputClass -> {
95-
if (name.endsWith(INPUT_SUFFIX, true) || this.isInputOnlyLocationRestricted()) {
96-
name
97-
} else {
98-
"$name$INPUT_SUFFIX"
99-
}
100-
}
92+
isInputClass -> if (name.endsWith(INPUT_SUFFIX, true)) name else "$name$INPUT_SUFFIX"
10193
else -> name
10294
}
10395
}
10496

105-
private fun KClass<*>.isInputOnlyLocationRestricted(): Boolean = findAnnotation<GraphQLValidObjectLocations>()
106-
?.locations
107-
?.all { it == GraphQLValidObjectLocations.Locations.INPUT_OBJECT }
108-
?: false
109-
11097
internal fun KClass<*>.getQualifiedName(): String = this.qualifiedName.orEmpty()
11198

11299
internal fun KClass<*>.isPublic(): Boolean = this.visibility == KVisibility.PUBLIC

generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateInputObjectTest.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class GenerateInputObjectTest : TypeTestHelper() {
5050
val myField: String = "car"
5151
}
5252

53-
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
54-
class InputAndObjectLocation {
55-
val myField: String = "car"
56-
}
57-
5853
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT])
5954
class OutputOnly {
6055
val myField: String = "car"
@@ -110,18 +105,6 @@ class GenerateInputObjectTest : TypeTestHelper() {
110105
}
111106
}
112107

113-
@Test
114-
fun `input only objects are not suffixed with 'Input'`() {
115-
val result = generateInputObject(generator, InputOnly::class)
116-
assertEquals("InputOnly", result.name)
117-
}
118-
119-
@Test
120-
fun `input and object located objects are suffixed with 'Input'`() {
121-
val result = generateInputObject(generator, InputAndObjectLocation::class)
122-
assertEquals("InputAndObjectLocationInput", result.name)
123-
}
124-
125108
@Test
126109
fun `output only objects throw an exception`() {
127110
assertFailsWith(InvalidObjectLocationException::class) {

website/docs/schema-generator/writing-schemas/arguments.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ This behavior is true for all arguments except for the special classes for the [
2525
Query, Mutation, and Subscription function arguments are automatically converted to GraphQL input fields. GraphQL makes a
2626
distinction between input and output types and requires unique names for all the types. Since we can use the same
2727
objects for input and output in our Kotlin functions, `graphql-kotlin-schema-generator` will automatically append
28-
an `Input` suffix to the GraphQL name of input objects, unless the type is [restricted to being used for
29-
input only](../customizing-schemas/restricting-input-output.md).
28+
an `Input` suffix to the GraphQL name of input objects.
3029

3130
For example, the following code:
3231

0 commit comments

Comments
 (0)