From e1ca748832c5a0124bb451ca3883ff5cda056278 Mon Sep 17 00:00:00 2001 From: Matt Bossenbroek Date: Fri, 19 Apr 2024 14:34:13 -0700 Subject: [PATCH] Add support for aliases in queries --- .../expected/client/QueryProjection.kt | 10 +++++-- .../expected/client/QueryProjection.kt | 10 +++++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 11 ++++--- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 10 +++++-- .../expected/client/QueryProjection.kt | 10 +++++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 7 +++-- .../client/EntityConnectionProjection.kt | 13 +++++---- .../expected/client/EntityEdgeProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 13 +++++---- .../expected/client/CarProjection.kt | 6 ++-- .../expected/client/EngineProjection.kt | 7 +++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../client/EntityConnectionProjection.kt | 13 +++++---- .../expected/client/EntityEdgeProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 13 +++++---- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/MyTypeProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/PersonProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/BirdProjection.kt | 16 ++++++---- .../expected/client/DogProjection.kt | 16 ++++++---- .../expected/client/PetProjection.kt | 16 ++++++---- .../expected/client/DogProjection.kt | 6 ++-- .../expected/client/PetProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/FruitProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 6 ++-- .../expected/client/StoneFruitProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 11 ++++--- .../expected/client/QueryProjection.kt | 3 +- .../test/QueryTest.kt | 29 +++++++++++++++++++ .../expected/client/QueryProjection.kt | 11 ++++--- .../union/expected/client/QueryProjection.kt | 7 +++-- .../expected/client/QueryProjection.kt | 9 ++++-- .../client/SearchResultPageProjection.kt | 6 ++-- .../expected/client/QueryProjection.kt | 7 +++-- .../kotlin2/GenerateKotlin2ClientTypes.kt | 3 +- .../graphql/dgs/codegen/Kotlin2Core.kt | 16 +++++----- 49 files changed, 275 insertions(+), 142 deletions(-) diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsForInputTypes/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsForInputTypes/expected/client/QueryProjection.kt index a62032cc8..701c071aa 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsForInputTypes/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsForInputTypes/expected/client/QueryProjection.kt @@ -2,11 +2,15 @@ package com.netflix.graphql.dgs.codegen.cases.constantsForInputTypes.expected.cl import com.netflix.graphql.dgs.codegen.GraphQLProjection import com.netflix.graphql.dgs.codegen.cases.constantsForInputTypes.expected.types.PersonFilter +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(filter: PersonFilter? = default("filter"), - _projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection, "filter" to filter) + public fun people( + _alias: String? = null, + filter: PersonFilter? = default("filter"), + _projection: PersonProjection.() -> PersonProjection, + ): QueryProjection { + field(_alias, "people", PersonProjection(), _projection, "filter" to filter) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInputTypes/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInputTypes/expected/client/QueryProjection.kt index a3a1f28b0..6fe4cf51b 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInputTypes/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInputTypes/expected/client/QueryProjection.kt @@ -2,11 +2,15 @@ package com.netflix.graphql.dgs.codegen.cases.constantsWithExtendedInputTypes.ex import com.netflix.graphql.dgs.codegen.GraphQLProjection import com.netflix.graphql.dgs.codegen.cases.constantsWithExtendedInputTypes.expected.types.PersonFilter +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(filter: PersonFilter? = default("filter"), - _projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection, "filter" to filter) + public fun people( + _alias: String? = null, + filter: PersonFilter? = default("filter"), + _projection: PersonProjection.() -> PersonProjection, + ): QueryProjection { + field(_alias, "people", PersonProjection(), _projection, "filter" to filter) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInterface/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInterface/expected/client/QueryProjection.kt index 8e4bd0a10..12afdff26 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInterface/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedInterface/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.constantsWithExtendedInterface.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedQuery/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedQuery/expected/client/QueryProjection.kt index 5f03cb2c4..c7c4b07ca 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedQuery/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedQuery/expected/client/QueryProjection.kt @@ -1,15 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.constantsWithExtendedQuery.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } - public fun friends(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("friends", PersonProjection(), _projection) + public fun friends(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "friends", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedTypes/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedTypes/expected/client/QueryProjection.kt index 58fe18140..8959f039f 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedTypes/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/constantsWithExtendedTypes/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.constantsWithExtendedTypes.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassDocs/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassDocs/expected/client/QueryProjection.kt index 1f095908c..b07446737 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassDocs/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassDocs/expected/client/QueryProjection.kt @@ -2,11 +2,15 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassDocs.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection import com.netflix.graphql.dgs.codegen.cases.dataClassDocs.expected.types.MovieFilter +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun search(movieFilter: MovieFilter, _projection: MovieProjection.() -> MovieProjection): - QueryProjection { - field("search", MovieProjection(), _projection, "movieFilter" to movieFilter) + public fun search( + _alias: String? = null, + movieFilter: MovieFilter, + _projection: MovieProjection.() -> MovieProjection, + ): QueryProjection { + field(_alias, "search", MovieProjection(), _projection, "movieFilter" to movieFilter) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassFieldDocs/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassFieldDocs/expected/client/QueryProjection.kt index 0568b1af4..7b2fbf955 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassFieldDocs/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassFieldDocs/expected/client/QueryProjection.kt @@ -2,11 +2,15 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassFieldDocs.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection import com.netflix.graphql.dgs.codegen.cases.dataClassFieldDocs.expected.types.MovieFilter +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun search(movieFilter: MovieFilter, _projection: MovieProjection.() -> MovieProjection): - QueryProjection { - field("search", MovieProjection(), _projection, "movieFilter" to movieFilter) + public fun search( + _alias: String? = null, + movieFilter: MovieFilter, + _projection: MovieProjection.() -> MovieProjection, + ): QueryProjection { + field(_alias, "search", MovieProjection(), _projection, "movieFilter" to movieFilter) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWIthNoFields/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWIthNoFields/expected/client/QueryProjection.kt index 8c211655e..d63a002b7 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWIthNoFields/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWIthNoFields/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWIthNoFields.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun me(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("me", PersonProjection(), _projection) + public fun me(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "me", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithBooleanField/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithBooleanField/expected/client/QueryProjection.kt index be5af3f9e..6374ac88f 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithBooleanField/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithBooleanField/expected/client/QueryProjection.kt @@ -1,11 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithBooleanField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun test(_projection: RequiredTestTypeProjection.() -> RequiredTestTypeProjection): - QueryProjection { - field("test", RequiredTestTypeProjection(), _projection) + public fun test(_alias: String? = null, + _projection: RequiredTestTypeProjection.() -> RequiredTestTypeProjection): QueryProjection { + field(_alias, "test", RequiredTestTypeProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityConnectionProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityConnectionProjection.kt index 3e266ae39..5f045ee50 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityConnectionProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityConnectionProjection.kt @@ -1,17 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeclaredScalars.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class EntityConnectionProjection : GraphQLProjection() { - public fun pageInfo(_projection: PageInfoProjection.() -> PageInfoProjection): - EntityConnectionProjection { - field("pageInfo", PageInfoProjection(), _projection) + public fun pageInfo(_alias: String? = null, + _projection: PageInfoProjection.() -> PageInfoProjection): EntityConnectionProjection { + field(_alias, "pageInfo", PageInfoProjection(), _projection) return this } - public fun edges(_projection: EntityEdgeProjection.() -> EntityEdgeProjection): - EntityConnectionProjection { - field("edges", EntityEdgeProjection(), _projection) + public fun edges(_alias: String? = null, + _projection: EntityEdgeProjection.() -> EntityEdgeProjection): EntityConnectionProjection { + field(_alias, "edges", EntityEdgeProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityEdgeProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityEdgeProjection.kt index afbeb21c7..61177d3a7 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityEdgeProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/EntityEdgeProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeclaredScalars.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class EntityEdgeProjection : GraphQLProjection() { public val cursor: EntityEdgeProjection @@ -9,8 +10,9 @@ public class EntityEdgeProjection : GraphQLProjection() { return this } - public fun node(_projection: EntityProjection.() -> EntityProjection): EntityEdgeProjection { - field("node", EntityProjection(), _projection) + public fun node(_alias: String? = null, _projection: EntityProjection.() -> EntityProjection): + EntityEdgeProjection { + field(_alias, "node", EntityProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/QueryProjection.kt index cd45546d4..1cd601c8b 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeclaredScalars/expected/client/QueryProjection.kt @@ -1,17 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeclaredScalars.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun entity(_projection: EntityProjection.() -> EntityProjection): QueryProjection { - field("entity", EntityProjection(), _projection) + public fun entity(_alias: String? = null, _projection: EntityProjection.() -> EntityProjection): + QueryProjection { + field(_alias, "entity", EntityProjection(), _projection) return this } - public - fun entityConnection(_projection: EntityConnectionProjection.() -> EntityConnectionProjection): - QueryProjection { - field("entityConnection", EntityConnectionProjection(), _projection) + public fun entityConnection(_alias: String? = null, + _projection: EntityConnectionProjection.() -> EntityConnectionProjection): QueryProjection { + field(_alias, "entityConnection", EntityConnectionProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/CarProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/CarProjection.kt index be3f36c41..b4428fb67 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/CarProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/CarProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeeplyNestedComplexField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class CarProjection : GraphQLProjection() { public val make: CarProjection @@ -15,8 +16,9 @@ public class CarProjection : GraphQLProjection() { return this } - public fun engine(_projection: EngineProjection.() -> EngineProjection): CarProjection { - field("engine", EngineProjection(), _projection) + public fun engine(_alias: String? = null, _projection: EngineProjection.() -> EngineProjection): + CarProjection { + field(_alias, "engine", EngineProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/EngineProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/EngineProjection.kt index 3d24bd5e1..55d9178a3 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/EngineProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/EngineProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeeplyNestedComplexField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class EngineProjection : GraphQLProjection() { public val type: EngineProjection @@ -21,9 +22,9 @@ public class EngineProjection : GraphQLProjection() { return this } - public fun performance(_projection: PerformanceProjection.() -> PerformanceProjection): - EngineProjection { - field("performance", PerformanceProjection(), _projection) + public fun performance(_alias: String? = null, + _projection: PerformanceProjection.() -> PerformanceProjection): EngineProjection { + field(_alias, "performance", PerformanceProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/QueryProjection.kt index 7acb3b439..e62affb18 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithDeeplyNestedComplexField/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithDeeplyNestedComplexField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun cars(_projection: CarProjection.() -> CarProjection): QueryProjection { - field("cars", CarProjection(), _projection) + public fun cars(_alias: String? = null, _projection: CarProjection.() -> CarProjection): + QueryProjection { + field(_alias, "cars", CarProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithExtendedInterface/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithExtendedInterface/expected/client/QueryProjection.kt index a69f168d1..f64d676df 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithExtendedInterface/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithExtendedInterface/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithExtendedInterface.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterface/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterface/expected/client/QueryProjection.kt index 224bab404..30b7bd26b 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterface/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterface/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithInterface.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterfaceInheritance/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterfaceInheritance/expected/client/QueryProjection.kt index dfaa2a460..193f1aff0 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterfaceInheritance/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithInterfaceInheritance/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithInterfaceInheritance.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithListProperties/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithListProperties/expected/client/QueryProjection.kt index 717af733a..118a11483 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithListProperties/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithListProperties/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithListProperties.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedInterfaces/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedInterfaces/expected/client/QueryProjection.kt index 7749ffa85..b604e143b 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedInterfaces/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedInterfaces/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithMappedInterfaces.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun products(_projection: ProductProjection.() -> ProductProjection): QueryProjection { - field("products", ProductProjection(), _projection) + public fun products(_alias: String? = null, + _projection: ProductProjection.() -> ProductProjection): QueryProjection { + field(_alias, "products", ProductProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityConnectionProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityConnectionProjection.kt index e48ea36d9..e1d014458 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityConnectionProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityConnectionProjection.kt @@ -1,17 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithMappedTypes.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class EntityConnectionProjection : GraphQLProjection() { - public fun pageInfo(_projection: PageInfoProjection.() -> PageInfoProjection): - EntityConnectionProjection { - field("pageInfo", PageInfoProjection(), _projection) + public fun pageInfo(_alias: String? = null, + _projection: PageInfoProjection.() -> PageInfoProjection): EntityConnectionProjection { + field(_alias, "pageInfo", PageInfoProjection(), _projection) return this } - public fun edges(_projection: EntityEdgeProjection.() -> EntityEdgeProjection): - EntityConnectionProjection { - field("edges", EntityEdgeProjection(), _projection) + public fun edges(_alias: String? = null, + _projection: EntityEdgeProjection.() -> EntityEdgeProjection): EntityConnectionProjection { + field(_alias, "edges", EntityEdgeProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityEdgeProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityEdgeProjection.kt index 897cb9c22..2aedb416f 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityEdgeProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/EntityEdgeProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithMappedTypes.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class EntityEdgeProjection : GraphQLProjection() { public val cursor: EntityEdgeProjection @@ -9,8 +10,9 @@ public class EntityEdgeProjection : GraphQLProjection() { return this } - public fun node(_projection: EntityProjection.() -> EntityProjection): EntityEdgeProjection { - field("node", EntityProjection(), _projection) + public fun node(_alias: String? = null, _projection: EntityProjection.() -> EntityProjection): + EntityEdgeProjection { + field(_alias, "node", EntityProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/QueryProjection.kt index a83aff410..6e2924cb7 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithMappedTypes/expected/client/QueryProjection.kt @@ -1,17 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithMappedTypes.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun entity(_projection: EntityProjection.() -> EntityProjection): QueryProjection { - field("entity", EntityProjection(), _projection) + public fun entity(_alias: String? = null, _projection: EntityProjection.() -> EntityProjection): + QueryProjection { + field(_alias, "entity", EntityProjection(), _projection) return this } - public - fun entityConnection(_projection: EntityConnectionProjection.() -> EntityConnectionProjection): - QueryProjection { - field("entityConnection", EntityConnectionProjection(), _projection) + public fun entityConnection(_alias: String? = null, + _projection: EntityConnectionProjection.() -> EntityConnectionProjection): QueryProjection { + field(_alias, "entityConnection", EntityConnectionProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableAndInterface/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableAndInterface/expected/client/QueryProjection.kt index aeae84bab..849286d6a 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableAndInterface/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableAndInterface/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithNonNullableAndInterface.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableComplexType/expected/client/MyTypeProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableComplexType/expected/client/MyTypeProjection.kt index 7bd55c787..d67e98843 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableComplexType/expected/client/MyTypeProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableComplexType/expected/client/MyTypeProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithNonNullableComplexType.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class MyTypeProjection : GraphQLProjection() { - public fun other(_projection: OtherTypeProjection.() -> OtherTypeProjection): MyTypeProjection { - field("other", OtherTypeProjection(), _projection) + public fun other(_alias: String? = null, + _projection: OtherTypeProjection.() -> OtherTypeProjection): MyTypeProjection { + field(_alias, "other", OtherTypeProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableListOfNullableValues/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableListOfNullableValues/expected/client/QueryProjection.kt index 80cf787d2..ea3565c01 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableListOfNullableValues/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableListOfNullableValues/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithNonNullableListOfNullableValues.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableProperties/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableProperties/expected/client/QueryProjection.kt index b1ddf513c..17b30b1a1 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableProperties/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithNonNullableProperties/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithNonNullableProperties.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/PersonProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/PersonProjection.kt index 83796a3ce..bf1a084f8 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/PersonProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/PersonProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithRecursiveField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class PersonProjection : GraphQLProjection() { public val firstname: PersonProjection @@ -15,8 +16,9 @@ public class PersonProjection : GraphQLProjection() { return this } - public fun friends(_projection: PersonProjection.() -> PersonProjection): PersonProjection { - field("friends", PersonProjection(), _projection) + public fun friends(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + PersonProjection { + field(_alias, "friends", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/QueryProjection.kt index 99daaeed3..a85774072 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithRecursiveField/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithRecursiveField.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithStringProperties/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithStringProperties/expected/client/QueryProjection.kt index 42ab08131..77ba8cd9a 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithStringProperties/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/dataClassWithStringProperties/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.dataClassWithStringProperties.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/BirdProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/BirdProjection.kt index 1226e25aa..a6b2f666e 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/BirdProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/BirdProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithInterfaceFields.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class BirdProjection : GraphQLProjection() { public val id: BirdProjection @@ -21,18 +22,21 @@ public class BirdProjection : GraphQLProjection() { return this } - public fun mother(_projection: BirdProjection.() -> BirdProjection): BirdProjection { - field("mother", BirdProjection(), _projection) + public fun mother(_alias: String? = null, _projection: BirdProjection.() -> BirdProjection): + BirdProjection { + field(_alias, "mother", BirdProjection(), _projection) return this } - public fun father(_projection: BirdProjection.() -> BirdProjection): BirdProjection { - field("father", BirdProjection(), _projection) + public fun father(_alias: String? = null, _projection: BirdProjection.() -> BirdProjection): + BirdProjection { + field(_alias, "father", BirdProjection(), _projection) return this } - public fun parents(_projection: BirdProjection.() -> BirdProjection): BirdProjection { - field("parents", BirdProjection(), _projection) + public fun parents(_alias: String? = null, _projection: BirdProjection.() -> BirdProjection): + BirdProjection { + field(_alias, "parents", BirdProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/DogProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/DogProjection.kt index 37fdca7f7..4861c6da5 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/DogProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/DogProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithInterfaceFields.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class DogProjection : GraphQLProjection() { public val id: DogProjection @@ -21,18 +22,21 @@ public class DogProjection : GraphQLProjection() { return this } - public fun mother(_projection: DogProjection.() -> DogProjection): DogProjection { - field("mother", DogProjection(), _projection) + public fun mother(_alias: String? = null, _projection: DogProjection.() -> DogProjection): + DogProjection { + field(_alias, "mother", DogProjection(), _projection) return this } - public fun father(_projection: DogProjection.() -> DogProjection): DogProjection { - field("father", DogProjection(), _projection) + public fun father(_alias: String? = null, _projection: DogProjection.() -> DogProjection): + DogProjection { + field(_alias, "father", DogProjection(), _projection) return this } - public fun parents(_projection: DogProjection.() -> DogProjection): DogProjection { - field("parents", DogProjection(), _projection) + public fun parents(_alias: String? = null, _projection: DogProjection.() -> DogProjection): + DogProjection { + field(_alias, "parents", DogProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/PetProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/PetProjection.kt index 3ca1290f9..df1ad3f6e 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/PetProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFields/expected/client/PetProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithInterfaceFields.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class PetProjection : GraphQLProjection() { public val id: PetProjection @@ -21,18 +22,21 @@ public class PetProjection : GraphQLProjection() { return this } - public fun mother(_projection: PetProjection.() -> PetProjection): PetProjection { - field("mother", PetProjection(), _projection) + public fun mother(_alias: String? = null, _projection: PetProjection.() -> PetProjection): + PetProjection { + field(_alias, "mother", PetProjection(), _projection) return this } - public fun father(_projection: PetProjection.() -> PetProjection): PetProjection { - field("father", PetProjection(), _projection) + public fun father(_alias: String? = null, _projection: PetProjection.() -> PetProjection): + PetProjection { + field(_alias, "father", PetProjection(), _projection) return this } - public fun parents(_projection: PetProjection.() -> PetProjection): PetProjection { - field("parents", PetProjection(), _projection) + public fun parents(_alias: String? = null, _projection: PetProjection.() -> PetProjection): + PetProjection { + field(_alias, "parents", PetProjection(), _projection) return this } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/DogProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/DogProjection.kt index 69b67adda..8c536d2ea 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/DogProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/DogProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithInterfaceFieldsOfDifferentType.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class DogProjection : GraphQLProjection() { public val name: DogProjection @@ -9,8 +10,9 @@ public class DogProjection : GraphQLProjection() { return this } - public fun diet(_projection: VegetarianProjection.() -> VegetarianProjection): DogProjection { - field("diet", VegetarianProjection(), _projection) + public fun diet(_alias: String? = null, + _projection: VegetarianProjection.() -> VegetarianProjection): DogProjection { + field(_alias, "diet", VegetarianProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/PetProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/PetProjection.kt index ef5e49202..c4f1886a4 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/PetProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithInterfaceFieldsOfDifferentType/expected/client/PetProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithInterfaceFieldsOfDifferentType.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class PetProjection : GraphQLProjection() { public val name: PetProjection @@ -9,8 +10,9 @@ public class PetProjection : GraphQLProjection() { return this } - public fun diet(_projection: DietProjection.() -> DietProjection): PetProjection { - field("diet", DietProjection(), _projection) + public fun diet(_alias: String? = null, _projection: DietProjection.() -> DietProjection): + PetProjection { + field(_alias, "diet", DietProjection(), _projection) return this } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithNonNullableFields/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithNonNullableFields/expected/client/QueryProjection.kt index 0bc6afdf1..7045b9412 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithNonNullableFields/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceClassWithNonNullableFields/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceClassWithNonNullableFields.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/FruitProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/FruitProjection.kt index 2a87b5b0c..254ec9adf 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/FruitProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/FruitProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceWithInterfaceInheritance.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class FruitProjection : GraphQLProjection() { - public fun seeds(_projection: SeedProjection.() -> SeedProjection): FruitProjection { - field("seeds", SeedProjection(), _projection) + public fun seeds(_alias: String? = null, _projection: SeedProjection.() -> SeedProjection): + FruitProjection { + field(_alias, "seeds", SeedProjection(), _projection) return this } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/QueryProjection.kt index 3abf122d1..94503020c 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/QueryProjection.kt @@ -1,10 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceWithInterfaceInheritance.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun fruits(_projection: FruitProjection.() -> FruitProjection): QueryProjection { - field("fruits", FruitProjection(), _projection) + public fun fruits(_alias: String? = null, _projection: FruitProjection.() -> FruitProjection): + QueryProjection { + field(_alias, "fruits", FruitProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/StoneFruitProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/StoneFruitProjection.kt index f73f5f500..6e89892f2 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/StoneFruitProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/interfaceWithInterfaceInheritance/expected/client/StoneFruitProjection.kt @@ -1,6 +1,7 @@ package com.netflix.graphql.dgs.codegen.cases.interfaceWithInterfaceInheritance.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class StoneFruitProjection : GraphQLProjection() { public val fuzzy: StoneFruitProjection @@ -9,8 +10,9 @@ public class StoneFruitProjection : GraphQLProjection() { return this } - public fun seeds(_projection: SeedProjection.() -> SeedProjection): StoneFruitProjection { - field("seeds", SeedProjection(), _projection) + public fun seeds(_alias: String? = null, _projection: SeedProjection.() -> SeedProjection): + StoneFruitProjection { + field(_alias, "seeds", SeedProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithType/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithType/expected/client/QueryProjection.kt index 50265e47e..8eb006615 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithType/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithType/expected/client/QueryProjection.kt @@ -1,15 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.projectionWithType.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun person(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("person", PersonProjection(), _projection) + public fun person(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "person", PersonProjection(), _projection) return this } - public fun people(_projection: PersonProjection.() -> PersonProjection): QueryProjection { - field("people", PersonProjection(), _projection) + public fun people(_alias: String? = null, _projection: PersonProjection.() -> PersonProjection): + QueryProjection { + field(_alias, "people", PersonProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/expected/client/QueryProjection.kt index d4f012890..fc927dac6 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/expected/client/QueryProjection.kt @@ -6,12 +6,13 @@ import kotlin.String public class QueryProjection : GraphQLProjection() { public fun person( + _alias: String? = null, a1: String? = default("a1"), a2: String, a3: I? = default("a3"), _projection: PersonProjection.() -> PersonProjection, ): QueryProjection { - field("person", PersonProjection(), _projection, "a1" to a1 , "a2" to a2 , "a3" to a3) + field(_alias, "person", PersonProjection(), _projection, "a1" to a1 , "a2" to a2 , "a3" to a3) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/test/QueryTest.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/test/QueryTest.kt index 61fa9bd74..a809790c5 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/test/QueryTest.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithTypeAndArgs/test/QueryTest.kt @@ -52,4 +52,33 @@ class QueryTest { query ) } + + @Test + fun testQueryWithAlias() { + val query = DgsClient.buildQuery { + person(_alias= "person1", a2 = "person1") { + firstname + } + person(_alias= "person2", a2 = "person2") { + firstname + } + } + + assertEquals( + """{ + | __typename + | person1: person(a2: "person1") { + | __typename + | firstname + | } + | person2: person(a2: "person2") { + | __typename + | firstname + | } + |} + | + """.trimMargin(), + query + ) + } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithUnion/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithUnion/expected/client/QueryProjection.kt index 8feedac01..160726b71 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithUnion/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/projectionWithUnion/expected/client/QueryProjection.kt @@ -1,15 +1,18 @@ package com.netflix.graphql.dgs.codegen.cases.projectionWithUnion.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun u(_projection: UProjection.() -> UProjection): QueryProjection { - field("u", UProjection(), _projection) + public fun u(_alias: String? = null, _projection: UProjection.() -> UProjection): + QueryProjection { + field(_alias, "u", UProjection(), _projection) return this } - public fun us(_projection: UProjection.() -> UProjection): QueryProjection { - field("us", UProjection(), _projection) + public fun us(_alias: String? = null, _projection: UProjection.() -> UProjection): + QueryProjection { + field(_alias, "us", UProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/union/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/union/expected/client/QueryProjection.kt index 3ccd516d8..c51f37059 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/union/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/union/expected/client/QueryProjection.kt @@ -1,11 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.union.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun search(_projection: SearchResultProjection.() -> SearchResultProjection): - QueryProjection { - field("search", SearchResultProjection(), _projection) + public fun search(_alias: String? = null, + _projection: SearchResultProjection.() -> SearchResultProjection): QueryProjection { + field(_alias, "search", SearchResultProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/QueryProjection.kt index 5700b7627..877d22d98 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/QueryProjection.kt @@ -4,9 +4,12 @@ import com.netflix.graphql.dgs.codegen.GraphQLProjection import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun search(text: String, - _projection: SearchResultPageProjection.() -> SearchResultPageProjection): QueryProjection { - field("search", SearchResultPageProjection(), _projection, "text" to text) + public fun search( + _alias: String? = null, + text: String, + _projection: SearchResultPageProjection.() -> SearchResultPageProjection, + ): QueryProjection { + field(_alias, "search", SearchResultPageProjection(), _projection, "text" to text) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/SearchResultPageProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/SearchResultPageProjection.kt index 624b1e6af..2dbdfb19c 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/SearchResultPageProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionTypesWithoutInterfaceCanDeserialize/expected/client/SearchResultPageProjection.kt @@ -1,11 +1,13 @@ package com.netflix.graphql.dgs.codegen.cases.unionTypesWithoutInterfaceCanDeserialize.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class SearchResultPageProjection : GraphQLProjection() { - public fun items(_projection: SearchResultProjection.() -> SearchResultProjection): + public fun items(_alias: String? = null, + _projection: SearchResultProjection.() -> SearchResultProjection): SearchResultPageProjection { - field("items", SearchResultProjection(), _projection) + field(_alias, "items", SearchResultProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionWithExtendedType/expected/client/QueryProjection.kt b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionWithExtendedType/expected/client/QueryProjection.kt index b26921e01..7f05dca30 100644 --- a/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionWithExtendedType/expected/client/QueryProjection.kt +++ b/graphql-dgs-codegen-core/src/integTest/kotlin/com/netflix/graphql/dgs/codegen/cases/unionWithExtendedType/expected/client/QueryProjection.kt @@ -1,11 +1,12 @@ package com.netflix.graphql.dgs.codegen.cases.unionWithExtendedType.expected.client import com.netflix.graphql.dgs.codegen.GraphQLProjection +import kotlin.String public class QueryProjection : GraphQLProjection() { - public fun search(_projection: SearchResultProjection.() -> SearchResultProjection): - QueryProjection { - field("search", SearchResultProjection(), _projection) + public fun search(_alias: String? = null, + _projection: SearchResultProjection.() -> SearchResultProjection): QueryProjection { + field(_alias, "search", SearchResultProjection(), _projection) return this } } diff --git a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin2/GenerateKotlin2ClientTypes.kt b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin2/GenerateKotlin2ClientTypes.kt index 758006aa8..4f77a0606 100644 --- a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin2/GenerateKotlin2ClientTypes.kt +++ b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/kotlin2/GenerateKotlin2ClientTypes.kt @@ -115,11 +115,12 @@ 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(projection) .returns(typeName) .addStatement( - """field(%S, %T(), _projection%L)""", + """field(_alias, %S, %T(), _projection%L)""", field.name, projectionType, field.inputValueDefinitions.joinToString(" ") { """, "${it.name}" to ${it.name}""" } diff --git a/graphql-dgs-codegen-shared-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/Kotlin2Core.kt b/graphql-dgs-codegen-shared-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/Kotlin2Core.kt index 10131e10f..ae67e0382 100644 --- a/graphql-dgs-codegen-shared-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/Kotlin2Core.kt +++ b/graphql-dgs-codegen-shared-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/Kotlin2Core.kt @@ -124,6 +124,7 @@ abstract class GraphQLProjection(defaultFields: Set = setOf("__typename" } protected fun field( + alias: String? = null, name: String, projection: T, projectionFields: T.() -> T, @@ -132,13 +133,14 @@ abstract class GraphQLProjection(defaultFields: Set = setOf("__typename" val defaults = DefaultTracker.getAndClear(this::class.qualifiedName!!) projectionFields.invoke(projection) - builder.selection( - Field.newField() - .name(name) - .arguments(arguments(args.toList(), defaults)) - .selectionSet(projection.builder.build()) - .build() - ) + val fieldBuilder = Field.newField() + .name(name) + .arguments(arguments(args.toList(), defaults)) + .selectionSet(projection.builder.build()) + + alias?.also { fieldBuilder.alias(it) } + + builder.selection(fieldBuilder.build()) } protected fun fragment(