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 capitalized field names if flattenModels is true #4154

Merged
merged 13 commits into from
Jun 3, 2022

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Jun 1, 2022

  • If flattenModels is true, then it's OK to have field names with the same name as the corresponding model - disable the validation in that case.
  • Fix a few other cases where there were still name conflicts (Adapter and Selections)

Related to #4152

@netlify
Copy link

netlify bot commented Jun 1, 2022

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit 10d1211
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/6298c0620a9a2400092098ff

@@ -68,7 +68,8 @@ class CompiledSelectionsBuilder(
}

private fun List<GQLSelection>.walk(name: String, private: Boolean, parentType: String): List<FieldSpec> {
val propertyName = resolveNameClashes(usedNames, context.layout.propertyName(name))
val maybeEscapedName = if (private) context.layout.escapedPropertyName(name) else context.layout.propertyName(name)
val propertyName = resolveNameClashes(usedNames, maybeEscapedName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the only case where this is public is the root field? In that case, you could rename the root field to __root (technically source breaking but I think that's ok?) and escape indiscriminately, just like for variables?

All in all, I think I'd do this:

  • __typename -> never escape
  • __root -> never escape
  • variables -> always escape
  • add a new compiledSelectionsName() that would always escape.

Copy link
Contributor

Choose a reason for hiding this comment

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

Digging into this again. Do you remember why we needed to escape the compiled selections? They look like this:

public object TestQuerySelections {
  private val __onDroid: List<CompiledSelection> = listOf(..)
  private val __hero: List<CompiledSelection> = listOf(..)
  // ...
  public val __root: List<CompiledSelection> = listOf(..)
}

This is all private (except __root) and this file has some code to resolve name clashes:

private fun resolveNameClashes(usedNames: MutableSet<String>, modelName: String): String {
. So escaping doesn't sound needed? Do you remember the details?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it looks like escaping is unnecessary - not sure why we did this 😅 Maybe we overlooked the fact that only __root is public?

@BoD BoD force-pushed the allow-capitalized-field-names branch from 4dc8cad to 96caf49 Compare June 2, 2022 13:21
@martinbonnin
Copy link
Contributor

🚀

@BoD BoD merged commit d6baba8 into main Jun 3, 2022
@BoD BoD deleted the allow-capitalized-field-names branch June 3, 2022 09:40
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.

None yet

2 participants