Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve alias handling in client generation #1763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ private fun calculateSelectedFields(
selectionSet.selections.forEach { selection ->
when (selection) {
is Field -> {
result.add(path + selection.name)
val fieldName = selection.alias ?: selection.name
result.add(path + fieldName)
if (selection.selectionSet != null) {
result.addAll(calculateSelectedFields(context, targetType, selection.selectionSet, "$path${selection.name}."))
result.addAll(calculateSelectedFields(context, targetType, selection.selectionSet, "$path$fieldName."))
}
}
is InlineFragment -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query AliasNestedQuery {
first: complexObjectQuery {
nameA: name
}
second: complexObjectQuery {
nameB: name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.expediagroup.graphql.generated

import com.expediagroup.graphql.client.Generated
import com.expediagroup.graphql.client.types.GraphQLClientRequest
import com.expediagroup.graphql.generated.aliasnestedquery.ComplexObject
import com.expediagroup.graphql.generated.aliasnestedquery.ComplexObject2
import kotlin.String
import kotlin.reflect.KClass

public const val ALIAS_NESTED_QUERY: String =
"query AliasNestedQuery {\n first: complexObjectQuery {\n nameA: name\n }\n second: complexObjectQuery {\n nameB: name\n }\n}"

@Generated
public class AliasNestedQuery : GraphQLClientRequest<AliasNestedQuery.Result> {
public override val query: String = ALIAS_NESTED_QUERY

public override val operationName: String = "AliasNestedQuery"

public override fun responseType(): KClass<AliasNestedQuery.Result> =
AliasNestedQuery.Result::class

@Generated
public data class Result(
/**
* Query returning an object that references another object
*/
public val first: ComplexObject,
/**
* Query returning an object that references another object
*/
public val second: ComplexObject2,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.expediagroup.graphql.generated.aliasnestedquery

import com.expediagroup.graphql.client.Generated
import kotlin.String

/**
* Multi line description of a complex type.
* This is a second line of the paragraph.
* This is final line of the description.
*/
@Generated
public data class ComplexObject(
/**
* Some object name
*/
public val nameA: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.expediagroup.graphql.generated.aliasnestedquery

import com.expediagroup.graphql.client.Generated
import kotlin.String

/**
* Multi line description of a complex type.
* This is a second line of the paragraph.
* This is final line of the description.
*/
@Generated
public data class ComplexObject2(
/**
* Some object name
*/
public val nameB: String,
)