-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make class consolidation configurable (#106)
- Loading branch information
1 parent
5df5385
commit e92c452
Showing
9 changed files
with
350 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/unit/should_honor_class_consolidation_config/codegen.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GraphQLKotlinCodegenConfig } from "../../../src/plugin"; | ||
|
||
export default { | ||
classConsolidationEnabled: false, | ||
} satisfies GraphQLKotlinCodegenConfig; |
170 changes: 170 additions & 0 deletions
170
test/unit/should_honor_class_consolidation_config/expected.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package com.kotlin.generated | ||
|
||
import com.expediagroup.graphql.generator.annotations.* | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToConsolidateWithConfig( | ||
val field: List<String>? = null, | ||
val field2: NestedTypeToConsolidateWithConfig? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToConsolidateWithConfigInput( | ||
val field: List<String>? = null, | ||
val field2: NestedTypeToConsolidateWithConfigInput? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class NestedTypeToConsolidateWithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class NestedTypeToConsolidateWithConfigInput( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLDescription("A description for MyTypeToConsolidate2") | ||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToConsolidate2WithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToConsolidate2WithConfigInput( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToConsolidate3WithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLDescription("It ignores the description on the input when consolidating") | ||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToConsolidate3WithConfigInput( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLDescription("It always uses the type description when consolidating") | ||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToConsolidate4WithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLDescription("A description for MyTypeToConsolidateInput4") | ||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToConsolidate4WithConfigInput( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeNotToConsolidateWithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLDescription("The type name must exactly match in order to consolidate") | ||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToNotConsolidateWithConfigInput( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToNotConsolidate2WithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeInputToNotConsolidate2WithConfig( | ||
val field: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeWhereFieldsDoNotMatchWithConfig( | ||
val field: String? = null, | ||
val field2: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeWhereFieldsDoNotMatchWithConfigInput( | ||
val field: String? = null, | ||
val field2: Int? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeToConsolidateParentWithConfig( | ||
val field: MyTypeToConsolidateWithConfig? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeToConsolidateInputParentWithConfig( | ||
val field: MyTypeToConsolidateWithConfigInput? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
open class MyTypeToConsolidateParent2WithConfig { | ||
open fun field(input: MyTypeToConsolidateWithConfigInput, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyTypeToConsolidateParent2WithConfig.field must be implemented.") | ||
} | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeNotToConsolidateParentWithConfig( | ||
val field: MyTypeNotToConsolidate2WithConfig? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeNotToConsolidateParentWithConfigInput( | ||
val field: MyTypeNotToConsolidate2WithConfigInput? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeNotToConsolidate2WithConfig( | ||
val field1: String? = null, | ||
val field2: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeNotToConsolidate2WithConfigInput( | ||
val field1: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MySuperSetTypeWithConfig( | ||
val field: String? = null, | ||
val field2: String? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MySuperSetTypeWithConfigInput( | ||
val field: String? = null, | ||
val field2: String? = null, | ||
val field3: Int? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) | ||
data class MyTypeWithEnumsWithConfig( | ||
val field1: List<Enum1WithConfig>? = null, | ||
val field2: List<Enum2WithConfig>? = null | ||
) | ||
|
||
@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) | ||
data class MyTypeWithEnumsWithConfigInput( | ||
val field1: List<Enum1WithConfig>? = null, | ||
val field2: List<Enum2WithConfig>? = null | ||
) | ||
|
||
enum class Enum1WithConfig { | ||
This, | ||
That; | ||
|
||
companion object { | ||
fun findByName(name: String, ignoreCase: Boolean = false): Enum1WithConfig? = values().find { it.name.equals(name, ignoreCase = ignoreCase) } | ||
} | ||
} | ||
|
||
enum class Enum2WithConfig { | ||
The_Other; | ||
|
||
companion object { | ||
fun findByName(name: String, ignoreCase: Boolean = false): Enum2WithConfig? = values().find { it.name.equals(name, ignoreCase = ignoreCase) } | ||
} | ||
} |
Oops, something went wrong.