Skip to content

Commit abdbfa4

Browse files
amondnetdwilkolek
authored andcommitted
Add a new configuration option typeSuffix and typePrefix to the CodeGenConfig class and update the code generation methods to append the affixes to the generated type names.
* **CodeGenConfig**: Add a new configuration option `typeSuffix` and `typePrefix` to the `CodeGenConfig` class. * **Java DataTypeGenerator**: Update the `generate` method to append the `typeSuffix` and `typePrefix` to the generated type names. * **Kotlin DataTypeGenerator**: Update the `generate` method to append the `typeSuffix` and `typePrefix` to the generated type names.
1 parent 5dfd192 commit abdbfa4

File tree

27 files changed

+592
-10
lines changed

27 files changed

+592
-10
lines changed

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/Kotlin2CodeGenTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ class Kotlin2CodeGenTest {
7777
)
7878
else -> emptyMap()
7979
},
80+
typePrefix =
81+
when (testName) {
82+
"dataClassWithPrefix" -> "Dgs"
83+
"inputWithPrefix" -> "Dgs"
84+
else -> ""
85+
},
86+
typeSuffix =
87+
when (testName) {
88+
"dataClassWithSuffix" -> "Type"
89+
"inputWithSuffix" -> "Type"
90+
else -> ""
91+
},
8092
),
8193
).generate()
8294

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected
2+
3+
import com.netflix.graphql.dgs.client.codegen.InputValueSerializerInterface
4+
import com.netflix.graphql.dgs.codegen.GraphQLProjection
5+
import com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.client.QueryProjection
6+
import graphql.language.OperationDefinition
7+
import kotlin.String
8+
9+
public object DgsClient {
10+
public fun buildQuery(inputValueSerializer: InputValueSerializerInterface? = null,
11+
_projection: QueryProjection.() -> QueryProjection): String =
12+
GraphQLProjection.asQuery(OperationDefinition.Operation.QUERY,
13+
QueryProjection(inputValueSerializer), _projection)
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected
2+
3+
import kotlin.String
4+
5+
public object DgsConstants {
6+
public const val QUERY_TYPE: String = "Query"
7+
8+
public object QUERY {
9+
public const val TYPE_NAME: String = "Query"
10+
11+
public const val Search: String = "search"
12+
13+
public object SEARCH_INPUT_ARGUMENT {
14+
public const val MovieFilter: String = "movieFilter"
15+
}
16+
}
17+
18+
public object MOVIE {
19+
public const val TYPE_NAME: String = "Movie"
20+
21+
public const val Title: String = "title"
22+
}
23+
24+
public object MOVIEFILTER {
25+
public const val TYPE_NAME: String = "MovieFilter"
26+
27+
public const val TitleFilter: String = "titleFilter"
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.client
2+
3+
import com.netflix.graphql.dgs.client.codegen.InputValueSerializerInterface
4+
import com.netflix.graphql.dgs.codegen.GraphQLProjection
5+
6+
public class MovieProjection(
7+
inputValueSerializer: InputValueSerializerInterface? = null,
8+
) : GraphQLProjection(inputValueSerializer) {
9+
public val title: MovieProjection
10+
get() {
11+
field("title")
12+
return this
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.client
2+
3+
import com.netflix.graphql.dgs.client.codegen.InputValueSerializerInterface
4+
import com.netflix.graphql.dgs.codegen.GraphQLProjection
5+
import com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.types.DgsMovieFilter
6+
import kotlin.String
7+
8+
public class QueryProjection(
9+
inputValueSerializer: InputValueSerializerInterface? = null,
10+
) : GraphQLProjection(inputValueSerializer) {
11+
public fun search(
12+
movieFilter: DgsMovieFilter,
13+
_alias: String? = null,
14+
_projection: MovieProjection.() -> MovieProjection,
15+
): QueryProjection {
16+
field(_alias, "search", MovieProjection(inputValueSerializer), _projection, "movieFilter" to
17+
movieFilter)
18+
return this
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.types
2+
3+
import com.fasterxml.jackson.`annotation`.JsonIgnoreProperties
4+
import com.fasterxml.jackson.`annotation`.JsonProperty
5+
import com.fasterxml.jackson.`annotation`.JsonTypeInfo
6+
import com.fasterxml.jackson.databind.`annotation`.JsonDeserialize
7+
import com.fasterxml.jackson.databind.`annotation`.JsonPOJOBuilder
8+
import java.lang.IllegalStateException
9+
import kotlin.String
10+
import kotlin.jvm.JvmName
11+
12+
/**
13+
* Movies are fun to watch.
14+
* They also work well as examples in GraphQL.
15+
*/
16+
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
17+
@JsonDeserialize(builder = DgsMovie.Builder::class)
18+
public class DgsMovie(
19+
title: () -> String? = titleDefault,
20+
) {
21+
private val __title: () -> String? = title
22+
23+
@get:JvmName("getTitle")
24+
public val title: String?
25+
get() = __title.invoke()
26+
27+
public companion object {
28+
private val titleDefault: () -> String? =
29+
{ throw IllegalStateException("Field `title` was not requested") }
30+
}
31+
32+
@JsonPOJOBuilder
33+
@JsonIgnoreProperties("__typename")
34+
public class Builder {
35+
private var title: () -> String? = titleDefault
36+
37+
@JsonProperty("title")
38+
public fun withTitle(title: String?): Builder = this.apply {
39+
this.title = { title }
40+
}
41+
42+
public fun build(): DgsMovie = DgsMovie(
43+
title = title,
44+
)
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.types
2+
3+
import com.fasterxml.jackson.`annotation`.JsonProperty
4+
import com.netflix.graphql.dgs.codegen.GraphQLInput
5+
import kotlin.Any
6+
import kotlin.Pair
7+
import kotlin.String
8+
import kotlin.collections.List
9+
10+
/**
11+
* Example filter for Movies.
12+
*
13+
* It takes a title and such.
14+
*/
15+
public data class DgsMovieFilter(
16+
@JsonProperty("titleFilter")
17+
public val titleFilter: String? = default<DgsMovieFilter, String?>("titleFilter", null),
18+
) : GraphQLInput() {
19+
override fun fields(): List<Pair<String, Any?>> = listOf("titleFilter" to titleFilter)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.netflix.graphql.dgs.codegen.cases.dataClassWithPrefix.expected.types
2+
3+
import com.fasterxml.jackson.`annotation`.JsonIgnoreProperties
4+
import com.fasterxml.jackson.`annotation`.JsonProperty
5+
import com.fasterxml.jackson.`annotation`.JsonTypeInfo
6+
import com.fasterxml.jackson.databind.`annotation`.JsonDeserialize
7+
import com.fasterxml.jackson.databind.`annotation`.JsonPOJOBuilder
8+
import java.lang.IllegalStateException
9+
import kotlin.jvm.JvmName
10+
11+
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
12+
@JsonDeserialize(builder = DgsQuery.Builder::class)
13+
public class DgsQuery(
14+
search: () -> DgsMovie? = searchDefault,
15+
) {
16+
private val __search: () -> DgsMovie? = search
17+
18+
@get:JvmName("getSearch")
19+
public val search: DgsMovie?
20+
get() = __search.invoke()
21+
22+
public companion object {
23+
private val searchDefault: () -> DgsMovie? =
24+
{ throw IllegalStateException("Field `search` was not requested") }
25+
}
26+
27+
@JsonPOJOBuilder
28+
@JsonIgnoreProperties("__typename")
29+
public class Builder {
30+
private var search: () -> DgsMovie? = searchDefault
31+
32+
@JsonProperty("search")
33+
public fun withSearch(search: DgsMovie?): Builder = this.apply {
34+
this.search = { search }
35+
}
36+
37+
public fun build(): DgsQuery = DgsQuery(
38+
search = search,
39+
)
40+
}
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type Query {
2+
search(movieFilter: MovieFilter!): Movie
3+
}
4+
5+
"""
6+
Movies are fun to watch.
7+
They also work well as examples in GraphQL.
8+
"""
9+
type Movie {
10+
title: String
11+
}
12+
13+
"""
14+
Example filter for Movies.
15+
16+
It takes a title and such.
17+
"""
18+
input MovieFilter {
19+
titleFilter: String
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.netflix.graphql.dgs.codegen.cases.inputWithPrefix.expected
2+
3+
import com.netflix.graphql.dgs.client.codegen.InputValueSerializerInterface
4+
import com.netflix.graphql.dgs.codegen.GraphQLProjection
5+
import com.netflix.graphql.dgs.codegen.cases.inputWithPrefix.expected.client.QueryProjection
6+
import graphql.language.OperationDefinition
7+
import kotlin.String
8+
9+
public object DgsClient {
10+
public fun buildQuery(inputValueSerializer: InputValueSerializerInterface? = null,
11+
_projection: QueryProjection.() -> QueryProjection): String =
12+
GraphQLProjection.asQuery(OperationDefinition.Operation.QUERY,
13+
QueryProjection(inputValueSerializer), _projection)
14+
}

0 commit comments

Comments
 (0)