Skip to content

Commit

Permalink
Kotlin/Scala: combining multiple projections #985
Browse files Browse the repository at this point in the history
  • Loading branch information
kobylynskyi committed Feb 20, 2023
1 parent 7799ed2 commit 70d3bbf
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 35 deletions.
10 changes: 10 additions & 0 deletions src/main/resources/templates/kotlin-lang/parametrized_input.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ data class ${className}(
</#if>
) : GraphQLParametrizedInput {

override fun deepCopy(): ${className} {
val parametrizedInput = ${className}()
<#if fields?has_content>
<#list fields as field>
parametrizedInput.${field.name}(this.${field.name})
</#list>
</#if>
return parametrizedInput
}

override fun toString(): String {
val joiner = StringJoiner(", ", "( ", " )")
<#list fields as field>
Expand Down
14 changes: 11 additions & 3 deletions src/main/resources/templates/kotlin-lang/response_projection.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import java.util.Objects
<#list annotations as annotation>
@${annotation}
</#list>
open class ${className} : GraphQLResponseProjection() {
open class ${className} : GraphQLResponseProjection {

constructor(): super()

constructor(projection: ${className}): super(projection)

constructor(projections: List<${className}>): super(projections)

<#if fields?has_content && generateAllMethodInProjection>
private val projectionDepthOnFields: MutableMap<String, Int> by lazy { mutableMapOf<String, Int>() }
Expand Down Expand Up @@ -63,21 +69,23 @@ open class ${className} : GraphQLResponseProjection() {
fun ${field.methodName}(<#if field.type?has_content>subProjection: ${field.type}</#if>): ${className} = ${field.methodName}(<#if field.parametrizedInputClassName?has_content></#if>null<#if field.type?has_content>, subProjection</#if>)

fun ${field.methodName}(alias: String?<#if field.type?has_content>, subProjection: ${field.type}</#if>): ${className} {
fields.add(GraphQLResponseField("${field.name}").alias(alias)<#if field.type?has_content>.projection(subProjection)</#if>)
`add$`(GraphQLResponseField("${field.name}").alias(alias)<#if field.type?has_content>.projection(subProjection)</#if>)
return this
}

<#if field.parametrizedInputClassName?has_content>
fun ${field.methodName}(input: ${field.parametrizedInputClassName}<#if field.type?has_content>, subProjection: ${field.type}</#if>): ${className} = ${field.methodName}(null, input<#if field.type?has_content>, subProjection</#if>)

fun ${field.methodName}(alias: String?, input: ${field.parametrizedInputClassName}<#if field.type?has_content>, subProjection: ${field.type}</#if>): ${className} {
fields.add(GraphQLResponseField("${field.name}").alias(alias).parameters(input)<#if field.type?has_content>.projection(subProjection)</#if>)
`add$`(GraphQLResponseField("${field.name}").alias(alias).parameters(input)<#if field.type?has_content>.projection(subProjection)</#if>)
return this
}

</#if>
</#list>
</#if>
override fun `deepCopy$`(): ${className} = ${className}(this)

<#if equalsAndHashCode>
override fun equals(other: Any?): Boolean {
if (this === other) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/templates/scala-lang/parametrized_input.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ case class ${className}(
</#if>
) extends GraphQLParametrizedInput {

override def deepCopy(): ${className} {
val parametrizedInput = ${className}()
<#if fields?has_content>
<#list fields as field>
parametrizedInput.${field.name}(this.${field.name})
</#list>
</#if>
parametrizedInput
}

override def toString(): String = {<#--There is no Option[Seq[T]], Format is not supported in the generated code, so it is very difficult to write template for this format.-->
<#if fields?has_content>
scala.Seq(<#list fields as field><#assign getMethod = ".get"><#assign asJava = ".asJava">
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/templates/scala-lang/response_projection.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ import scala.collection.mutable.HashMap
</#list>
class ${className} extends GraphQLResponseProjection {

def this() = {
super()
}

def this(projection: ${className}) = {
super(projection)
}

def this(projections: scala.Seq[${className}]) = {
super(projections)
}

<#if fields?has_content && generateAllMethodInProjection>
private final lazy val projectionDepthOnFields = new HashMap[String, Int]

Expand Down Expand Up @@ -85,6 +97,8 @@ class ${className} extends GraphQLResponseProjection {
</#if>
</#list>
</#if>
override def deepCopy$(): ${className} = ${className}(this)

<#if equalsAndHashCode>
override def equals(obj: Any): Boolean = {
if (this == obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import java.util.Objects
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
open class SearchResultItemConnectionResponseProjection : GraphQLResponseProjection() {
open class SearchResultItemConnectionResponseProjection : GraphQLResponseProjection {

constructor(): super()

constructor(projection: SearchResultItemConnectionResponseProjection): super(projection)

constructor(projections: List<SearchResultItemConnectionResponseProjection>): super(projections)

private val projectionDepthOnFields: MutableMap<String, Int> by lazy { mutableMapOf<String, Int>() }

Expand Down Expand Up @@ -42,66 +48,68 @@ open class SearchResultItemConnectionResponseProjection : GraphQLResponseProject
fun codeCount(): SearchResultItemConnectionResponseProjection = codeCount(null)

fun codeCount(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("codeCount").alias(alias))
`add$`(GraphQLResponseField("codeCount").alias(alias))
return this
}

fun edges(subProjection: SearchResultItemEdgeResponseProjection): SearchResultItemConnectionResponseProjection = edges(null, subProjection)

fun edges(alias: String?, subProjection: SearchResultItemEdgeResponseProjection): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("edges").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("edges").alias(alias).projection(subProjection))
return this
}

fun issueCount(): SearchResultItemConnectionResponseProjection = issueCount(null)

fun issueCount(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("issueCount").alias(alias))
`add$`(GraphQLResponseField("issueCount").alias(alias))
return this
}

fun nodes(subProjection: SearchResultItemResponseProjection): SearchResultItemConnectionResponseProjection = nodes(null, subProjection)

fun nodes(alias: String?, subProjection: SearchResultItemResponseProjection): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("nodes").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("nodes").alias(alias).projection(subProjection))
return this
}

fun pageInfo(subProjection: PageInfoResponseProjection): SearchResultItemConnectionResponseProjection = pageInfo(null, subProjection)

fun pageInfo(alias: String?, subProjection: PageInfoResponseProjection): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("pageInfo").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("pageInfo").alias(alias).projection(subProjection))
return this
}

fun repositoryCount(): SearchResultItemConnectionResponseProjection = repositoryCount(null)

fun repositoryCount(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("repositoryCount").alias(alias))
`add$`(GraphQLResponseField("repositoryCount").alias(alias))
return this
}

fun userCount(): SearchResultItemConnectionResponseProjection = userCount(null)

fun userCount(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("userCount").alias(alias))
`add$`(GraphQLResponseField("userCount").alias(alias))
return this
}

fun wikiCount(): SearchResultItemConnectionResponseProjection = wikiCount(null)

fun wikiCount(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("wikiCount").alias(alias))
`add$`(GraphQLResponseField("wikiCount").alias(alias))
return this
}

fun typename(): SearchResultItemConnectionResponseProjection = typename(null)

fun typename(alias: String?): SearchResultItemConnectionResponseProjection {
fields.add(GraphQLResponseField("__typename").alias(alias))
`add$`(GraphQLResponseField("__typename").alias(alias))
return this
}

override fun `deepCopy$`(): SearchResultItemConnectionResponseProjection = SearchResultItemConnectionResponseProjection(this)

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -115,4 +123,4 @@ open class SearchResultItemConnectionResponseProjection : GraphQLResponseProject

override fun hashCode(): Int = Objects.hash(fields)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import java.util.Objects
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
open class SearchResultItemResponseProjection : GraphQLResponseProjection() {
open class SearchResultItemResponseProjection : GraphQLResponseProjection {

constructor(): super()

constructor(projection: SearchResultItemResponseProjection): super(projection)

constructor(projections: List<SearchResultItemResponseProjection>): super(projections)

private val projectionDepthOnFields: MutableMap<String, Int> by lazy { mutableMapOf<String, Int>() }

Expand All @@ -25,59 +31,61 @@ open class SearchResultItemResponseProjection : GraphQLResponseProjection() {
fun onApp(subProjection: AppResponseProjection): SearchResultItemResponseProjection = onApp(null, subProjection)

fun onApp(alias: String?, subProjection: AppResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on App").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on App").alias(alias).projection(subProjection))
return this
}

fun onRepository(subProjection: RepositoryResponseProjection): SearchResultItemResponseProjection = onRepository(null, subProjection)

fun onRepository(alias: String?, subProjection: RepositoryResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on Repository").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on Repository").alias(alias).projection(subProjection))
return this
}

fun onIssue(subProjection: IssueResponseProjection): SearchResultItemResponseProjection = onIssue(null, subProjection)

fun onIssue(alias: String?, subProjection: IssueResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on Issue").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on Issue").alias(alias).projection(subProjection))
return this
}

fun onOrganization(subProjection: OrganizationResponseProjection): SearchResultItemResponseProjection = onOrganization(null, subProjection)

fun onOrganization(alias: String?, subProjection: OrganizationResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on Organization").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on Organization").alias(alias).projection(subProjection))
return this
}

fun onUser(subProjection: UserResponseProjection): SearchResultItemResponseProjection = onUser(null, subProjection)

fun onUser(alias: String?, subProjection: UserResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on User").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on User").alias(alias).projection(subProjection))
return this
}

fun onMarketplaceListing(subProjection: MarketplaceListingResponseProjection): SearchResultItemResponseProjection = onMarketplaceListing(null, subProjection)

fun onMarketplaceListing(alias: String?, subProjection: MarketplaceListingResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on MarketplaceListing").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on MarketplaceListing").alias(alias).projection(subProjection))
return this
}

fun onPullRequest(subProjection: PullRequestResponseProjection): SearchResultItemResponseProjection = onPullRequest(null, subProjection)

fun onPullRequest(alias: String?, subProjection: PullRequestResponseProjection): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("...on PullRequest").alias(alias).projection(subProjection))
`add$`(GraphQLResponseField("...on PullRequest").alias(alias).projection(subProjection))
return this
}

fun typename(): SearchResultItemResponseProjection = typename(null)

fun typename(alias: String?): SearchResultItemResponseProjection {
fields.add(GraphQLResponseField("__typename").alias(alias))
`add$`(GraphQLResponseField("__typename").alias(alias))
return this
}

override fun `deepCopy$`(): SearchResultItemResponseProjection = SearchResultItemResponseProjection(this)

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -91,4 +99,4 @@ open class SearchResultItemResponseProjection : GraphQLResponseProjection() {

override fun hashCode(): Int = Objects.hash(fields)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
open class EventResponseProjection : GraphQLResponseProjection() {
open class EventResponseProjection : GraphQLResponseProjection {

constructor(): super()

constructor(projection: EventResponseProjection): super(projection)

constructor(projections: List<EventResponseProjection>): super(projections)

private val projectionDepthOnFields: MutableMap<String, Int> by lazy { mutableMapOf<String, Int>() }

Expand All @@ -22,9 +28,11 @@ open class EventResponseProjection : GraphQLResponseProjection() {
fun typename(): EventResponseProjection = typename(null)

fun typename(alias: String?): EventResponseProjection {
fields.add(GraphQLResponseField("__typename").alias(alias))
`add$`(GraphQLResponseField("__typename").alias(alias))
return this
}

override fun `deepCopy$`(): EventResponseProjection = EventResponseProjection(this)


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import java.util.Objects
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
open class CharResponseProjection : GraphQLResponseProjection() {
open class CharResponseProjection : GraphQLResponseProjection {

constructor(): super()

constructor(projection: CharResponseProjection): super(projection)

constructor(projections: List<CharResponseProjection>): super(projections)

private val projectionDepthOnFields: MutableMap<String, Int> by lazy { mutableMapOf<String, Int>() }

Expand All @@ -25,10 +31,12 @@ open class CharResponseProjection : GraphQLResponseProjection() {
fun typename(): CharResponseProjection = typename(null)

fun typename(alias: String?): CharResponseProjection {
fields.add(GraphQLResponseField("__typename").alias(alias))
`add$`(GraphQLResponseField("__typename").alias(alias))
return this
}

override fun `deepCopy$`(): CharResponseProjection = CharResponseProjection(this)

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -42,4 +50,4 @@ open class CharResponseProjection : GraphQLResponseProjection() {

override fun hashCode(): Int = Objects.hash(fields)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ data class QueryFunParametrizedInput(
val final: Int?
) : GraphQLParametrizedInput {

override fun deepCopy(): QueryFunParametrizedInput {
val parametrizedInput = QueryFunParametrizedInput()
parametrizedInput.final(this.final)
return parametrizedInput
}

override fun toString(): String {
val joiner = StringJoiner(", ", "( ", " )")
if (final != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ data class QueryPrivateParametrizedInput(
val createdAfter: java.time.ZonedDateTime?
) : GraphQLParametrizedInput {

override fun deepCopy(): QueryPrivateParametrizedInput {
val parametrizedInput = QueryPrivateParametrizedInput()
parametrizedInput.int(this.int)
parametrizedInput.new(this.new)
parametrizedInput.enum(this.enum)
parametrizedInput.createdAfter(this.createdAfter)
return parametrizedInput
}

override fun toString(): String {
val joiner = StringJoiner(", ", "( ", " )")
if (int != null) {
Expand Down
Loading

0 comments on commit 70d3bbf

Please sign in to comment.