From 053bce00d7983d6466a22b1cb5bf3ef963730051 Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Fri, 6 May 2022 11:53:18 -0700 Subject: [PATCH] Revert "feat(generator): avoid adding `input`-suffix for input-only classes (#1434)" (#1438) This reverts commit 0cca1e478b2e5f00ecbb8bb528b6440e83a1bc5b. --- .../internal/extensions/kClassExtensions.kt | 15 +-------------- .../internal/types/GenerateInputObjectTest.kt | 17 ----------------- .../writing-schemas/arguments.md | 3 +-- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt b/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt index ebb6a3352a..e8280831da 100644 --- a/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt +++ b/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt @@ -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 @@ -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 @@ -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() - ?.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 diff --git a/generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateInputObjectTest.kt b/generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateInputObjectTest.kt index e17bebcb85..d6a5689ea8 100644 --- a/generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateInputObjectTest.kt +++ b/generator/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/internal/types/GenerateInputObjectTest.kt @@ -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" @@ -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) { diff --git a/website/docs/schema-generator/writing-schemas/arguments.md b/website/docs/schema-generator/writing-schemas/arguments.md index 759805f452..175eb5f744 100644 --- a/website/docs/schema-generator/writing-schemas/arguments.md +++ b/website/docs/schema-generator/writing-schemas/arguments.md @@ -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: