Skip to content

Commit c0874e2

Browse files
Revert "feat: ability to specify @GraphQLName on input types w/o suffix (#1…" (#2034)
Reverts #1963 #2031
1 parent d05d13e commit c0874e2

File tree

3 files changed

+3
-44
lines changed

3 files changed

+3
-44
lines changed

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Expedia, Inc
2+
* Copyright 2022 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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
@@ -86,16 +84,12 @@ internal fun KClass<*>.isListType(isDirective: Boolean = false): Boolean = this.
8684

8785
@Throws(CouldNotGetNameOfKClassException::class)
8886
internal fun KClass<*>.getSimpleName(isInputClass: Boolean = false): String {
89-
val isInputOnlyLocation = this.findAnnotation<GraphQLValidObjectLocations>().let {
90-
it != null && it.locations.size == 1 && it.locations.contains(GraphQLValidObjectLocations.Locations.INPUT_OBJECT)
91-
}
92-
9387
val name = this.getGraphQLName()
9488
?: this.simpleName
9589
?: throw CouldNotGetNameOfKClassException(this)
9690

9791
return when {
98-
isInputClass -> if (name.endsWith(INPUT_SUFFIX, true) || isInputOnlyLocation) name else "$name$INPUT_SUFFIX"
92+
isInputClass -> if (name.endsWith(INPUT_SUFFIX, true)) name else "$name$INPUT_SUFFIX"
9993
else -> name
10094
}
10195
}

generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/extensions/KClassExtensionsTest.kt

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Expedia, Inc
2+
* Copyright 2022 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package com.expediagroup.graphql.generator.internal.extensions
1919
import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
2020
import com.expediagroup.graphql.generator.annotations.GraphQLName
2121
import com.expediagroup.graphql.generator.annotations.GraphQLUnion
22-
import com.expediagroup.graphql.generator.annotations.GraphQLValidObjectLocations
2322
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
2423
import com.expediagroup.graphql.generator.hooks.NoopSchemaGeneratorHooks
2524
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
@@ -78,13 +77,6 @@ open class KClassExtensionsTest {
7877
@GraphQLName("MyClassRenamedInput")
7978
class MyClassCustomNameInput
8079

81-
@GraphQLValidObjectLocations([GraphQLValidObjectLocations.Locations.INPUT_OBJECT])
82-
class MyInputClassWithoutSuffix
83-
84-
@GraphQLValidObjectLocations([GraphQLValidObjectLocations.Locations.INPUT_OBJECT])
85-
@GraphQLName("MyClass")
86-
class MyInputClassWithoutSuffixUsingCustomName
87-
8880
protected class MyProtectedClass
8981

9082
class MyPublicClass
@@ -386,10 +378,4 @@ open class KClassExtensionsTest {
386378
assertFalse(IgnoredClass::class.isValidAdditionalType(true))
387379
assertFalse(IgnoredClass::class.isValidAdditionalType(false))
388380
}
389-
390-
@Test
391-
fun `@GraphQLName does not apply input suffix on input only classes`() {
392-
assertEquals("MyInputClassWithoutSuffix", MyInputClassWithoutSuffix::class.getSimpleName(isInputClass = true))
393-
assertEquals("MyClass", MyInputClassWithoutSuffixUsingCustomName::class.getSimpleName(isInputClass = true))
394-
}
395381
}

website/docs/schema-generator/customizing-schemas/renaming-fields.md

-21
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,6 @@ type MyCustomName {
2020
}
2121
```
2222

23-
:::info
24-
By default, in order to differentiate between input and output types, all input type names are auto generated with additional
25-
`Input` suffix. Suffix is appended only if input type name does not already end with `Input`. If you would like to change this
26-
behavior and avoid extra suffix, you need to explicitly specify that this is an input only type.
27-
28-
```kotlin
29-
// GraphQL input object type name: MyInputType
30-
@GraphQLValidObjectLocations([GraphQLValidObjectLocations.Locations.INPUT_OBJECT])
31-
data class MyInputType(val id: ID)
32-
```
33-
34-
You can also rename input types
35-
36-
```kotlin
37-
// GraphQL input object type name: MyCustomInputType
38-
@GraphQLValidObjectLocations([GraphQLValidObjectLocations.Locations.INPUT_OBJECT])
39-
@GraphQLName("MyCustomInputType")
40-
data class MyInputType(val id: ID)
41-
```
42-
:::
43-
4423
## Known Issues
4524

4625
Due to how we deserialize input classes, if you rename a field of an input class or an enum value you must also annotate

0 commit comments

Comments
 (0)