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

Doesn't support a fragment with the same name of its type #184

Closed
filipealva opened this issue Nov 21, 2017 · 5 comments
Closed

Doesn't support a fragment with the same name of its type #184

filipealva opened this issue Nov 21, 2017 · 5 comments
Labels
codegen Issues related to or arising from code generation

Comments

@filipealva
Copy link

filipealva commented Nov 21, 2017

As we've discovered discussing in Apollo Slack, If I create a fragment with the same name of its type as the following:

fragment Center on Center {
  _id
  name
}

Everytime we call it from a query the query returns a QueryName.Data.Center type, even if we map and access it through the .fragments.center property of each result item.

screen shot 2017-11-21 at 14 01 05

@filipealva
Copy link
Author

@martijnwalraven any thoughts on where the cause of this issue can be? I mean, it is a apollo-ios issue or maybe the apollo-codegen is causing it?

I'm trying to figure out to see if I can contribute fixing it up, but I'm a little lost on the project :P if you can provide any info for me to track this bug it would be very helpful.

@martijnwalraven
Copy link
Contributor

The problem is not actually the fragment name being the same as the name of the type it is defined on, but the name of the query field being the same. In the generated code, we expect Center to refer to the fragment struct, but because AllCentersQuery.Data.Center is in scope, our reference is interpreted as that type instead.

So we need to disambiguate the fragments struct reference in the generated code. The relevant apollo-codegen code is here.

@designatednerd designatednerd added the codegen Issues related to or arising from code generation label Jul 10, 2019
@calvincestari
Copy link
Member

Hi 👋🏻 - after looking at this issue again in preparation for the upcoming 1.0 release we've decided not to take this request into 1.0. If this is important to you please let us know in this issue - thank you.

@zdesiree
Copy link

zdesiree commented Apr 26, 2023

With migrating our project to Apollo 1.x, this topic of naming the fragment the same as it's type came up again, but with a different problem. It results in a duplicated file name because of the Schema/Objects containing the same file name as the Fragments folder.
Is there any option to work around this, e.g. defining a prefixing for the file names only? So I don't have to rename all my fragments.

@calvincestari
Copy link
Member

@zdesiree - you can subscribe to #2598 for updates to the same issue that we're tracking in 1.0 releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Issues related to or arising from code generation
Projects
None yet
Development

No branches or pull requests

5 participants