Uh oh. Just added JS as a target to my multiplatfo...
# apollo-kotlin
s
Uh oh. Just added JS as a target to my multiplatform project where my GraphQL schema happens to declare a lot of types/fragments whatever with a “name” type defined in there like:
Copy code
type SomeType {
  name: String
}
And it’s crashing since JS doesn’t like it with error:
JavaScript name (name) generated for this declaration clashes with another declaration: fun name(): String
. Is there some way to automatically map those names to something else, maybe like “name_” or something smarter I must think about without annoying literally everyone about this limitation 😂 just like how we can map GraphQL types to Kotlin types?
False alarm I guess! It was crashing because the variable passed to the Query itself was named: “name” which means that the generated _Query data class was the one with the error. So I can just change that one variable and it doesn’t seem break during building!
m
Yea, changing variable names works. If that ever happens for fields, you can use aliases too
s
Yeah, but then it’d be on a per-field alias right? No way to make it global? I guess it wouldn’t be that bad with some search & replace automation
b
Interesting! The code gen escapes Java and Kotlin keywords, so maybe it could also escape JS keywords, although shouldn’t it be the job of the KotlinJS compiler? 🤔
m
I'm still unclear about what the rules are for JS. Looks like in this case, it's more about a clash (variable with the same name as method?) than the usage of a reserved keyword?
b
oh yeah not clear
s
Yeah there is an auto-generated
name
variable for all JS classes as far as I understand, it’s not a keyword in that case. But in any way, it doesn’t seem like you need to occupy your minds with this as it only was a problem for the variable names in the query itself, like here:
Copy code
query SomeQuery($name: String!) {
  query(name: $name) {
    // stuff
  }
}
Changing it to
Copy code
query SomeQuery($moreSpecificWord: String!) {
  query(name: $moreSpecificWord) {
    // stuff
  }
}
Compiles just fine as I can see it rn
👍 2