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

JavaScript name (name) generated for this declaration clashes with another declaration: val name: String #4640

Closed
ScottPierce opened this issue Jan 18, 2023 · 5 comments

Comments

@ScottPierce
Copy link

Version

3.7.1

Summary

mutation CreateCustomer($name: String!, $storeId: Int!) {
    createCustomer(input: {customer: {storeId: $storeId, name: $name}}) {
        customer {
            id
            storeId
            name
        }
    }
}
public data class CreateCustomerMutation(
  public val name: String,
  public val storeId: Int,
) : Mutation<CreateCustomerMutation.Data> {
  public override fun id(): String = OPERATION_ID

  public override fun document(): String = OPERATION_DOCUMENT

  public override fun name(): String = OPERATION_NAME

Steps to reproduce the behavior

Create a mutation with an external parameter with the name name. This will conflict with the parameter by the name of name.

The solution would be to change the name of the function name() to something less common, like operationName(), or mutationName(), etc. Another alternative would be to set the JsName annotation on the base class: @JsName("mutationName"). This will allow the same Kotlin api, but when compiled to JS, would actually use a different function for JS.

Logs

JavaScript name (name) generated for this declaration clashes with another declaration: val name: String
@BoD
Copy link
Contributor

BoD commented Jan 19, 2023

Thanks for reporting this! Will have a look, in the meantime can you give the parameter a different name?

@BoD
Copy link
Contributor

BoD commented Jan 19, 2023

Thanks for the tip about @JsName, I've done just that here.

@ScottPierce
Copy link
Author

Awesome! Thanks for the fast turn around - I wonder if it makes sense to do the same thing with document() while you are in there, although document is probably less common.

@BoD
Copy link
Contributor

BoD commented Jan 19, 2023

Thank you! That's a good point! I've thought about it but figured we should really name them with a reserved name, like __operation to avoid any clashes - but didn't want to break the symmetry with id, nor change its js name (not sure if that would be a breaking change). On the other hand, since there is an easy workaround, I didn't worry too much about it 😅 Maybe we can rename these fields in v4 (breaking changes allowed).

@BoD
Copy link
Contributor

BoD commented Mar 15, 2023

This has been released as part of v3.7.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants