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

Allow mapping scalars to simple generic types #6158

Merged
merged 2 commits into from
Sep 24, 2024
Merged

Allow mapping scalars to simple generic types #6158

merged 2 commits into from
Sep 24, 2024

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Sep 20, 2024

See #6156 and #3243. This is far from perfect but unlocks a few cases.

@BoD BoD requested a review from martinbonnin as a code owner September 20, 2024 17:07
Copy link

netlify bot commented Sep 20, 2024

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit 8b35e34
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/66f2cc1ad96364000862c8d3

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

2 possible improvements:

  1. Make it a proper parser for Kotlin type (unlocks dynamic, function types, variance, wildcards, type annotations, etc...)
    2. recognize some frequent auto imports (kotlin., kotlin.collections.) done

)
} else {
mapOf(
"Date" to ScalarInfo("java.util.Date"),
"URL" to ScalarInfo("kotlin.String", ExpressionAdapterInitializer("com.example.UrlAdapter")),
"ID" to ScalarInfo("kotlin.Long"),
"String" to ScalarInfo("kotlin.String", ExpressionAdapterInitializer("com.example.MyStringAdapter()")),
"ListOfString" to ScalarInfo("kotlin.collections.List<kotlin.String?>"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is quite the mouthful. I guess List<String?> doesn't work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried to make sure, but no, ClassName.bestGuess() expects a fully qualified name. I'll see if I can add a few shortcuts for String, List, etc.

Comment on lines +26 to +34
private fun String.withPackage(): String {
return if (this in commonKotlinTypes) {
"kotlin.${this}"
} else if (this in commonKotlinCollectionsTypes) {
"kotlin.collections.${this}"
} else {
this
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@BoD BoD merged commit c7f608d into main Sep 24, 2024
9 checks passed
@BoD BoD deleted the generic-scalars branch September 24, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants