File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed
generator/graphql-kotlin-schema-generator/src
main/kotlin/com/expediagroup/graphql/generator
test/kotlin/com/expediagroup/graphql/generator/internal/extensions
website/versioned_docs/version-8.x.x/schema-generator/writing-schemas Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2024 Expedia, Inc
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package com.expediagroup.graphql.generator.annotations
18+
19+ /* *
20+ * Do not add "Input" Suffix for input types.
21+ */
22+ @Target(AnnotationTarget .CLASS )
23+ annotation class GraphQLSkipInputSuffix
Original file line number Diff line number Diff line change 1616
1717package com.expediagroup.graphql.generator.internal.extensions
1818
19+ import com.expediagroup.graphql.generator.annotations.GraphQLSkipInputSuffix
1920import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
2021import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
2122import com.expediagroup.graphql.generator.internal.filters.functionFilters
@@ -28,6 +29,7 @@ import kotlin.reflect.KProperty
2829import kotlin.reflect.KVisibility
2930import kotlin.reflect.full.declaredMemberFunctions
3031import kotlin.reflect.full.declaredMemberProperties
32+ import kotlin.reflect.full.findAnnotation
3133import kotlin.reflect.full.findParameterByName
3234import kotlin.reflect.full.isSubclassOf
3335import kotlin.reflect.full.memberFunctions
@@ -84,12 +86,13 @@ internal fun KClass<*>.isListType(isDirective: Boolean = false): Boolean = this.
8486
8587@Throws(CouldNotGetNameOfKClassException ::class )
8688internal fun KClass <* >.getSimpleName (isInputClass : Boolean = false): String {
89+ val skipSuffix = this .findAnnotation<GraphQLSkipInputSuffix >() != null
8790 val name = this .getGraphQLName()
8891 ? : this .simpleName
8992 ? : throw CouldNotGetNameOfKClassException (this )
9093
9194 return when {
92- isInputClass -> if (name.endsWith(INPUT_SUFFIX , true )) name else " $name$INPUT_SUFFIX "
95+ isInputClass && ! skipSuffix -> if (name.endsWith(INPUT_SUFFIX , true )) name else " $name$INPUT_SUFFIX "
9396 else -> name
9497 }
9598}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package com.expediagroup.graphql.generator.internal.extensions
1818
1919import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
2020import com.expediagroup.graphql.generator.annotations.GraphQLName
21+ import com.expediagroup.graphql.generator.annotations.GraphQLSkipInputSuffix
2122import com.expediagroup.graphql.generator.annotations.GraphQLUnion
2223import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
2324import com.expediagroup.graphql.generator.hooks.NoopSchemaGeneratorHooks
@@ -74,6 +75,9 @@ open class KClassExtensionsTest {
7475
7576 class MyClassInput
7677
78+ @GraphQLSkipInputSuffix
79+ class MyTestClassSkipSuffix
80+
7781 @GraphQLName(" MyClassRenamedInput" )
7882 class MyClassCustomNameInput
7983
@@ -330,6 +334,11 @@ open class KClassExtensionsTest {
330334 assertEquals(" MyClassInput" , MyClassInput ::class .getSimpleName(true ))
331335 }
332336
337+ @Test
338+ fun `test input class name with skipped suffix` () {
339+ assertEquals(" MyTestClassSkipSuffix" , MyTestClassSkipSuffix ::class .getSimpleName(true ))
340+ }
341+
333342 @Test
334343 fun `test input class name with GraphQLName` () {
335344 assertEquals(" MyTestClassRenamedInput" , MyTestClassCustomName ::class .getSimpleName(true ))
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ input WidgetInput {
6161}
6262```
6363
64+ If you want to disable this behaviour for one of your types , you can add `@GraphQLSkipInputSuffix ` to your type .
65+
6466Note that only fields are exposed in the input objects . Functions will only be available on the GraphQL output types .
6567
6668:::caution
You can’t perform that action at this time.
0 commit comments