Skip to content

Commit 47e98f3

Browse files
authored
Merge pull request #682 from Netflix/feature/alias-fix
Kotlin2: Move aliases to the last position so they don't conflict with unnamed args
2 parents 8a6f6cf + f4c422e commit 47e98f3

File tree

8 files changed

+29
-7
lines changed

8 files changed

+29
-7
lines changed

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsForInputTypes/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class QueryProjection(
99
inputValueSerializer: InputValueSerializerInterface? = null,
1010
) : GraphQLProjection(inputValueSerializer) {
1111
public fun people(
12-
_alias: String? = null,
1312
filter: PersonFilter? = default<QueryProjection, PersonFilter?>("filter"),
13+
_alias: String? = null,
1414
_projection: PersonProjection.() -> PersonProjection,
1515
): QueryProjection {
1616
field(_alias, "people", PersonProjection(inputValueSerializer), _projection, "filter" to filter)

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInputTypes/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class QueryProjection(
99
inputValueSerializer: InputValueSerializerInterface? = null,
1010
) : GraphQLProjection(inputValueSerializer) {
1111
public fun people(
12-
_alias: String? = null,
1312
filter: PersonFilter? = default<QueryProjection, PersonFilter?>("filter"),
13+
_alias: String? = null,
1414
_projection: PersonProjection.() -> PersonProjection,
1515
): QueryProjection {
1616
field(_alias, "people", PersonProjection(inputValueSerializer), _projection, "filter" to filter)

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassDocs/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class QueryProjection(
99
inputValueSerializer: InputValueSerializerInterface? = null,
1010
) : GraphQLProjection(inputValueSerializer) {
1111
public fun search(
12-
_alias: String? = null,
1312
movieFilter: MovieFilter,
13+
_alias: String? = null,
1414
_projection: MovieProjection.() -> MovieProjection,
1515
): QueryProjection {
1616
field(_alias, "search", MovieProjection(inputValueSerializer), _projection, "movieFilter" to

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassFieldDocs/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class QueryProjection(
99
inputValueSerializer: InputValueSerializerInterface? = null,
1010
) : GraphQLProjection(inputValueSerializer) {
1111
public fun search(
12-
_alias: String? = null,
1312
movieFilter: MovieFilter,
13+
_alias: String? = null,
1414
_projection: MovieProjection.() -> MovieProjection,
1515
): QueryProjection {
1616
field(_alias, "search", MovieProjection(inputValueSerializer), _projection, "movieFilter" to

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class QueryProjection(
99
inputValueSerializer: InputValueSerializerInterface? = null,
1010
) : GraphQLProjection(inputValueSerializer) {
1111
public fun person(
12-
_alias: String? = null,
1312
a1: String? = default<QueryProjection, String?>("a1"),
1413
a2: String,
1514
a3: I? = default<QueryProjection, I?>("a3"),
15+
_alias: String? = null,
1616
_projection: PersonProjection.() -> PersonProjection,
1717
): QueryProjection {
1818
field(_alias, "person", PersonProjection(inputValueSerializer), _projection, "a1" to a1 , "a2"

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/test/QueryTest.kt

+22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ class QueryTest {
5353
)
5454
}
5555

56+
@Test
57+
fun testQueryWithUnnamedArgs() {
58+
val query = DgsClient.buildQuery {
59+
person("a1", "a2") {
60+
firstname
61+
}
62+
}
63+
64+
assertEquals(
65+
"""{
66+
| __typename
67+
| person(a1: "a1", a2: "a2") {
68+
| __typename
69+
| firstname
70+
| }
71+
|}
72+
|
73+
""".trimMargin(),
74+
query
75+
)
76+
}
77+
5678
@Test
5779
fun testQueryWithAlias() {
5880
val query = DgsClient.buildQuery {

graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/QueryProjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class QueryProjection(
88
inputValueSerializer: InputValueSerializerInterface? = null,
99
) : GraphQLProjection(inputValueSerializer) {
1010
public fun search(
11-
_alias: String? = null,
1211
text: String,
12+
_alias: String? = null,
1313
_projection: SearchResultPageProjection.() -> SearchResultPageProjection,
1414
): QueryProjection {
1515
field(_alias, "search", SearchResultPageProjection(inputValueSerializer), _projection, "text" to

graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin2/GenerateKotlin2ClientTypes.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ fun generateKotlin2ClientTypes(
121121
val (projectionType, projection) = projectionType(config.packageNameClient, projectionTypeName)
122122

123123
FunSpec.builder(field.name)
124-
.addParameter(ParameterSpec.builder("_alias", String::class.asTypeName().copy(nullable = true)).defaultValue("null").build())
125124
.addInputArgs(config, typeLookup, typeName, field.inputValueDefinitions)
125+
.addParameter(ParameterSpec.builder("_alias", String::class.asTypeName().copy(nullable = true)).defaultValue("null").build())
126126
.addParameter(projection)
127127
.returns(typeName)
128128
.addStatement(

0 commit comments

Comments
 (0)