diff --git a/src/utils/should-consolidate-types.ts b/src/utils/should-consolidate-types.ts index 9f07fce..1ba4768 100644 --- a/src/utils/should-consolidate-types.ts +++ b/src/utils/should-consolidate-types.ts @@ -71,7 +71,13 @@ function typesAreEquivalent( const matchingInputField = inputNode.astNode?.fields?.find( (inputField) => inputField.name.value === typeField.name.value, ); - if (!matchingInputField?.type) return false; + if ( + !matchingInputField?.type || + typeField.type.kind !== matchingInputField.type.kind + ) { + return false; + } + const baseTypeName = getBaseTypeNode(typeField.type).name.value; const baseInputTypeName = getBaseTypeNode(matchingInputField.type).name .value; diff --git a/test/unit/should_consolidate_input_and_output_types/expected.kt b/test/unit/should_consolidate_input_and_output_types/expected.kt index 8a34614..c501d82 100644 --- a/test/unit/should_consolidate_input_and_output_types/expected.kt +++ b/test/unit/should_consolidate_input_and_output_types/expected.kt @@ -128,3 +128,17 @@ enum class Enum2 { fun findByName(name: String, ignoreCase: Boolean = false): Enum2? = values().find { it.name.equals(name, ignoreCase = ignoreCase) } } } + +@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) +data class MyNullabilityType( + val field1: MyNestedNullabilityType +) + +@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) +data class MyNullabilityTypeInput( + val field1: MyNestedNullabilityType? = null +) + +data class MyNestedNullabilityType( + val field2: String +) diff --git a/test/unit/should_consolidate_input_and_output_types/schema.graphql b/test/unit/should_consolidate_input_and_output_types/schema.graphql index 5980638..86a0d79 100644 --- a/test/unit/should_consolidate_input_and_output_types/schema.graphql +++ b/test/unit/should_consolidate_input_and_output_types/schema.graphql @@ -131,6 +131,8 @@ input MySuperSetTypeInput { field3: Int } +# case where fields are different enum types + type MyTypeWithEnums { field1: [Enum1!] field2: [Enum2!] @@ -149,3 +151,21 @@ enum Enum1 { enum Enum2 { THE_OTHER } + +# case where fields have different nullability + +type MyNullabilityType { + field1: MyNestedNullabilityType! +} + +input MyNullabilityTypeInput { + field1: MyNestedNullabilityTypeInput +} + +type MyNestedNullabilityType { + field2: String! +} + +input MyNestedNullabilityTypeInput { + field2: String! +}