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

Type with "Companion" name causes compile error #4629

Closed
jorrhe opened this issue Jan 12, 2023 · 6 comments · Fixed by #4630
Closed

Type with "Companion" name causes compile error #4629

jorrhe opened this issue Jan 12, 2023 · 6 comments · Fixed by #4630

Comments

@jorrhe
Copy link

jorrhe commented Jan 12, 2023

Version

3.7.3

Summary

When a graphql schema contains a type with the name "Companion" it causes the project to not compile.

Steps to reproduce the behavior

  1. Create a schemea with a type named "Companion" ex:
type Companion{
   name: String
}
  1. Compile the project

Logs

Conflicting declarations: public companion object, public final data class Companion
@martinbonnin
Copy link
Contributor

martinbonnin commented Jan 12, 2023

Thanks for raising this 🙏 . We'll add auto escapes rules for that. In the meantime, you can workaround by using @targetName (source)

Add an extra.graphqls file next to your schema with these contents:

extend type Companion @targetName(name: "Companion_")

That should use Companion_ in the generated code. Hope this helps, let us know if that did!

@jorrhe
Copy link
Author

jorrhe commented Jan 12, 2023

Hi, thank you for responding so quick!

I've tried your solution but it didn't work, the same error appears on compilation. Do you think it may be related to having various schemas in the project?

This is an example of the folder structure I have with two schemas: one with a "Companion" type. I added the exta.graphqls file to the folder with the service2 schema, which is the schema that has the problem.

graphql/
├─ service1/
│  ├─ service1schema.graphqls
├─ service2/
│  ├─ extra.graphqls
│  ├─ service2schema.graphqls

On my app build.gradle I have defined the two apollo schemas like this:

apollo {

    service("service1"){
        srcDir("src/main/graphql/service1")
        packageName.set("com.test.apollo.service1")
    }

    service("service2"){
        srcDir("src/main/graphql/service2")
        packageName.set("com.test.apollo.service2")
    }

}

I hope this helps! Thank you again!

@martinbonnin
Copy link
Contributor

That should have worked 🤔 . Let me check quickly if I can reproduce.

@martinbonnin
Copy link
Contributor

martinbonnin commented Jan 12, 2023

Could it be that the issue is on a companion field (and not on the Companion type)? I don't have any issue with a class named Companion at the top level but indeed it fails if it's nested with another actual companion object.

Do you have anything like this in your queries?

query GetFoo {
  companion {
    bar
  }
}

If yes, then the workaround would be to use aliases in your query:

query GetFoo {
  companion_: companion {
    bar
  }
}

@jorrhe
Copy link
Author

jorrhe commented Jan 12, 2023

That's was it! Thank you for helping me!

@martinbonnin
Copy link
Contributor

Nice, thanks for confirming.
I'll keep this issue open to see if we can auto-escape this

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

Successfully merging a pull request may close this issue.

2 participants