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 16
16
17
17
package com.expediagroup.graphql.generator.internal.extensions
18
18
19
+ import com.expediagroup.graphql.generator.annotations.GraphQLSkipInputSuffix
19
20
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
20
21
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
21
22
import com.expediagroup.graphql.generator.internal.filters.functionFilters
@@ -28,6 +29,7 @@ import kotlin.reflect.KProperty
28
29
import kotlin.reflect.KVisibility
29
30
import kotlin.reflect.full.declaredMemberFunctions
30
31
import kotlin.reflect.full.declaredMemberProperties
32
+ import kotlin.reflect.full.findAnnotation
31
33
import kotlin.reflect.full.findParameterByName
32
34
import kotlin.reflect.full.isSubclassOf
33
35
import kotlin.reflect.full.memberFunctions
@@ -84,12 +86,13 @@ internal fun KClass<*>.isListType(isDirective: Boolean = false): Boolean = this.
84
86
85
87
@Throws(CouldNotGetNameOfKClassException ::class )
86
88
internal fun KClass <* >.getSimpleName (isInputClass : Boolean = false): String {
89
+ val skipSuffix = this .findAnnotation<GraphQLSkipInputSuffix >() != null
87
90
val name = this .getGraphQLName()
88
91
? : this .simpleName
89
92
? : throw CouldNotGetNameOfKClassException (this )
90
93
91
94
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 "
93
96
else -> name
94
97
}
95
98
}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package com.expediagroup.graphql.generator.internal.extensions
18
18
19
19
import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
20
20
import com.expediagroup.graphql.generator.annotations.GraphQLName
21
+ import com.expediagroup.graphql.generator.annotations.GraphQLSkipInputSuffix
21
22
import com.expediagroup.graphql.generator.annotations.GraphQLUnion
22
23
import com.expediagroup.graphql.generator.exceptions.CouldNotGetNameOfKClassException
23
24
import com.expediagroup.graphql.generator.hooks.NoopSchemaGeneratorHooks
@@ -74,6 +75,9 @@ open class KClassExtensionsTest {
74
75
75
76
class MyClassInput
76
77
78
+ @GraphQLSkipInputSuffix
79
+ class MyTestClassSkipSuffix
80
+
77
81
@GraphQLName(" MyClassRenamedInput" )
78
82
class MyClassCustomNameInput
79
83
@@ -330,6 +334,11 @@ open class KClassExtensionsTest {
330
334
assertEquals(" MyClassInput" , MyClassInput ::class .getSimpleName(true ))
331
335
}
332
336
337
+ @Test
338
+ fun `test input class name with skipped suffix` () {
339
+ assertEquals(" MyTestClassSkipSuffix" , MyTestClassSkipSuffix ::class .getSimpleName(true ))
340
+ }
341
+
333
342
@Test
334
343
fun `test input class name with GraphQLName` () {
335
344
assertEquals(" MyTestClassRenamedInput" , MyTestClassCustomName ::class .getSimpleName(true ))
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ input WidgetInput {
61
61
}
62
62
```
63
63
64
+ If you want to disable this behaviour for one of your types , you can add `@GraphQLSkipInputSuffix ` to your type .
65
+
64
66
Note that only fields are exposed in the input objects . Functions will only be available on the GraphQL output types .
65
67
66
68
:::caution
You can’t perform that action at this time.
0 commit comments