Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consolidation nullability #108

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utils/should-consolidate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/should_consolidate_input_and_output_types/expected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ input MySuperSetTypeInput {
field3: Int
}

# case where fields are different enum types

type MyTypeWithEnums {
field1: [Enum1!]
field2: [Enum2!]
Expand All @@ -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!
}