Skip to content

Commit aad9208

Browse files
committed
pass test
1 parent f43d0b4 commit aad9208

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/definitions/input.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export function buildInputObjectDefinition(
2727
return "";
2828
}
2929

30+
const typeNameWithoutInput = node.name.value.replace("Input", "");
31+
const correspondingType = schema.getType(typeNameWithoutInput);
32+
if (correspondingType) {
33+
return "";
34+
}
35+
3036
const classMembers = (node.fields ?? [])
3137
.map((arg) => {
3238
const typeToUse = buildTypeMetadata(arg.type, schema, config);

src/definitions/object.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export function buildObjectTypeDefinition(
3434
return "";
3535
}
3636

37+
const typeNameWithInput = `${node.name.value}Input`;
38+
const correspondingInput = schema.getType(typeNameWithInput);
39+
const inputOutputAnnotation = correspondingInput
40+
? "@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])\n"
41+
: "";
42+
3743
const annotations = buildAnnotations({
3844
config,
3945
definitionNode: node,
@@ -57,7 +63,7 @@ ${getDataClassMembers({ node, schema, config, completableFuture: true })}
5763
}`;
5864
}
5965

60-
return `${annotations}data class ${name}(
66+
return `${annotations}${inputOutputAnnotation}data class ${name}(
6167
${getDataClassMembers({ node, schema, config })}
6268
)${interfaceInheritance}`;
6369
}

test/unit/should_consolidate_input_and_output_types/expected.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ package com.kotlin.generated
22

33
import com.expediagroup.graphql.generator.annotations.*
44

5-
data class MyTypeToConsolidate1(
5+
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
6+
data class MyTypeToConsolidate(
67
val field: String? = null
78
)
89

910
@GraphQLDescription("A description for MyTypeToConsolidate2")
11+
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
1012
data class MyTypeToConsolidate2(
1113
val field: String? = null
1214
)
1315

16+
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
1417
data class MyTypeToConsolidate3(
1518
val field: String? = null
1619
)
1720

1821
@GraphQLDescription("It always uses the type description when consolidating")
22+
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT, GraphQLValidObjectLocations.Locations.OBJECT])
1923
data class MyTypeToConsolidate4(
2024
val field: String? = null
2125
)
@@ -24,6 +28,7 @@ data class MyTypeNotToConsolidate(
2428
val field: String? = null
2529
)
2630

31+
@GraphQLDescription("The type name must exactly match in order to consolidate")
2732
data class MyTypeToNotConsolidateInput(
2833
val field: String? = null
2934
)

0 commit comments

Comments
 (0)