Skip to content

Commit

Permalink
Merge pull request #682 from Netflix/feature/alias-fix
Browse files Browse the repository at this point in the history
Kotlin2: Move aliases to the last position so they don't conflict with unnamed args
  • Loading branch information
mbossenbroek authored Apr 22, 2024
2 parents 8a6f6cf + f4c422e commit 47e98f3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun people(
_alias: String? = null,
filter: PersonFilter? = default<QueryProjection, PersonFilter?>("filter"),
_alias: String? = null,
_projection: PersonProjection.() -> PersonProjection,
): QueryProjection {
field(_alias, "people", PersonProjection(inputValueSerializer), _projection, "filter" to filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun people(
_alias: String? = null,
filter: PersonFilter? = default<QueryProjection, PersonFilter?>("filter"),
_alias: String? = null,
_projection: PersonProjection.() -> PersonProjection,
): QueryProjection {
field(_alias, "people", PersonProjection(inputValueSerializer), _projection, "filter" to filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun search(
_alias: String? = null,
movieFilter: MovieFilter,
_alias: String? = null,
_projection: MovieProjection.() -> MovieProjection,
): QueryProjection {
field(_alias, "search", MovieProjection(inputValueSerializer), _projection, "movieFilter" to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun search(
_alias: String? = null,
movieFilter: MovieFilter,
_alias: String? = null,
_projection: MovieProjection.() -> MovieProjection,
): QueryProjection {
field(_alias, "search", MovieProjection(inputValueSerializer), _projection, "movieFilter" to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun person(
_alias: String? = null,
a1: String? = default<QueryProjection, String?>("a1"),
a2: String,
a3: I? = default<QueryProjection, I?>("a3"),
_alias: String? = null,
_projection: PersonProjection.() -> PersonProjection,
): QueryProjection {
field(_alias, "person", PersonProjection(inputValueSerializer), _projection, "a1" to a1 , "a2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ class QueryTest {
)
}

@Test
fun testQueryWithUnnamedArgs() {
val query = DgsClient.buildQuery {
person("a1", "a2") {
firstname
}
}

assertEquals(
"""{
| __typename
| person(a1: "a1", a2: "a2") {
| __typename
| firstname
| }
|}
|
""".trimMargin(),
query
)
}

@Test
fun testQueryWithAlias() {
val query = DgsClient.buildQuery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class QueryProjection(
inputValueSerializer: InputValueSerializerInterface? = null,
) : GraphQLProjection(inputValueSerializer) {
public fun search(
_alias: String? = null,
text: String,
_alias: String? = null,
_projection: SearchResultPageProjection.() -> SearchResultPageProjection,
): QueryProjection {
field(_alias, "search", SearchResultPageProjection(inputValueSerializer), _projection, "text" to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ fun generateKotlin2ClientTypes(
val (projectionType, projection) = projectionType(config.packageNameClient, projectionTypeName)

FunSpec.builder(field.name)
.addParameter(ParameterSpec.builder("_alias", String::class.asTypeName().copy(nullable = true)).defaultValue("null").build())
.addInputArgs(config, typeLookup, typeName, field.inputValueDefinitions)
.addParameter(ParameterSpec.builder("_alias", String::class.asTypeName().copy(nullable = true)).defaultValue("null").build())
.addParameter(projection)
.returns(typeName)
.addStatement(
Expand Down

0 comments on commit 47e98f3

Please sign in to comment.