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

Invalid Redeclaration of a Model #2438

Closed
hamedaakhlaghi opened this issue Aug 16, 2022 · 17 comments
Closed

Invalid Redeclaration of a Model #2438

hamedaakhlaghi opened this issue Aug 16, 2022 · 17 comments
Labels
awaiting response codegen Issues related to or arising from code generation

Comments

@hamedaakhlaghi
Copy link

our server has a model with two fields:

discount: Discount
deliveryDiscount: Discount

when I downloaded the schema there were two struct for Discount and I got this error :
/Users/hamed/Documents/workspaces/ice/Modules/Core/Network/Sources/Network/Schemas/Operations/cart.graphql.swift:5682:25: Invalid redeclaration of 'Discount'

when I remove one of them from my .graphql file everything is OK

I asked our other developers (android and front) they don't have this issue
could you please answer me?

@calvincestari
Copy link
Member

Hi @hamedaakhlaghi, thanks for the bug report. Can you tell me which version of apollo-ios you're using?

@calvincestari calvincestari added the codegen Issues related to or arising from code generation label Aug 16, 2022
@hamedaakhlaghi
Copy link
Author

@calvincestari your welcome, I tested "0.51.0", "0.52.0", "0.53.0"

@calvincestari
Copy link
Member

OK, I just wanted to clarify whether this was feedback for the upcoming 1.0 release, currently in beta.

Is Discount a custom scalar or a type?

@hamedaakhlaghi
Copy link
Author

Yes, it is a custom type with these fields
Screen Shot 2022-08-16 at 2 53 10 PM

@calvincestari
Copy link
Member

I tested "0.51.0", "0.52.0", "0.53.0"

Is this a new problem with these three versions, did the code generation work for you on an older version?

@hamedaakhlaghi
Copy link
Author

hamedaakhlaghi commented Aug 16, 2022

@calvincestari this model is one of our new models, Let me test it with the older versions, I'm in the middle of testing it with the beta version. could you please send me the exact version that you think there is not this problem?

@calvincestari
Copy link
Member

calvincestari commented Aug 16, 2022

could you please send me the exact version that you think there is not this problem?

We don't have any bug reports of this kind of problem with the current 0.53.0 version. I'm surprised why two fields of the same type would duplicate the Discount struct so I'm trying to narrow down whether this is the result of a recent change.

is The beta version not backward compatible?

1.0 is a breaking change, there are many changes and improvements to the API.

@hamedaakhlaghi
Copy link
Author

could you please send me the exact version that you think there is not this problem?

We don't have any bug reports of this kind of problem with the current 0.53.0 version. I'm surprised why two fields of the same type would duplicate the Discount struct so I'm trying to narrow down whether this is the result of a recent change.

is The beta version not backward compatible?

1.0 is a breaking change, there are many changes and improvements to the API.

I hope to find the correct version for resolving this issue

@calvincestari
Copy link
Member

Can you share some of the generated code - the structs where the duplication is happening?

@hamedaakhlaghi
Copy link
Author

Can you share some of the generated code - the structs where the duplication is happening?

sure, I will be sent it in 30 min

@hamedaakhlaghi
Copy link
Author

@calvincestari
cart.graphql.swift.zip

@AnthonyMDev
Copy link
Contributor

This is definitely odd behavior. I'm almost certain this won't exist in the 1.0 version, as we've re-written the entire code generation engine. While it is a breaking change, we hope the migration to 1.0 isn't terribly difficult or painful. In most cases, it shouldn't cause you to have to make massive re-writes, just setting up the new codegen and changing some call sites perhaps.

As for the old codegen, it might be more helpful if we could take a look at your schema as well. I understand that is probably sensitive data, so if you can't share it with us I understand. Or if you could share it with us privately rather than via a public link, I'd love to take a look at that.

I'll be honest, the reason we re-wrote the codegen engine for 1.0 is that the old codegen engine was buggy and very difficult to make changes to. If there is something wrong in your schema or operations that we can deduce to help resolve this great, but its unlikely that we are going to be able to allocate the resources to digging into the legacy code generation engine and fixing bugs there.

The 1.0 is very close to being stable now, and I highly recommend you being the process of migrating to this version when you are able to. Specifically because we don't intend to maintain the legacy codegen engine any longer. The 1.0 Beta 2 is going to be released soon (hopefully today!) and we expect that to be very very close to ready for a General Release.

@hamedaakhlaghi
Copy link
Author

hamedaakhlaghi commented Aug 16, 2022

@AnthonyMDev thank you for your effort, I'll send you the data that I have permission to share with you as soon as possible (to your email), is it OK?
also, let me know if there is any migration document for migrating to the new version.

This is definitely odd behavior. I'm almost certain this won't exist in the 1.0 version, as we've re-written the entire code generation engine. While it is a breaking change, we hope the migration to 1.0 isn't terribly difficult or painful. In most cases, it shouldn't cause you to have to make massive re-writes, just setting up the new codegen and changing some call sites perhaps.

As for the old codegen, it might be more helpful if we could take a look at your schema as well. I understand that is probably sensitive data, so if you can't share it with us I understand. Or if you could share it with us privately rather than via a public link, I'd love to take a look at that.

I'll be honest, the reason we re-wrote the codegen engine for 1.0 is that the old codegen engine was buggy and very difficult to make changes to. If there is something wrong in your schema or operations that we can deduce to help resolve this great, but its unlikely that we are going to be able to allocate the resources to digging into the legacy code generation engine and fixing bugs there.

The 1.0 is very close to being stable now, and I highly recommend you being the process of migrating to this version when you are able to. Specifically because we don't intend to maintain the legacy codegen engine any longer. The 1.0 Beta 2 is going to be released soon (hopefully today!) and we expect that to be very very close to ready for a General Release.

@calvincestari
Copy link
Member

Closing this issue due to inactivity - if this is still an issue please comment here and we can revisit.

@troyST
Copy link

troyST commented Mar 30, 2023

I'm experiencing an issue similar to this using 1.0.6.

In my case the schema contains something like:

type: Type!
types: [Type!]!

which is causing the Type struct to be generated twice leading to the Invalid redeclaration of 'Type' error

@calvincestari
Copy link
Member

@troyST I think what you're experiencing is described in #2850. The fix is for you to use a field alias and disambiguate the type names. see #2850 (comment). We're going to make the codegen engine detect this and provide a warning on how to fix but it won't automatically resolve the conflicting singular/plural name generation, you will still need to do that through a field alias.

@troyST
Copy link

troyST commented Mar 30, 2023

@calvincestari I will take a look at the linked issue. Thank you for the quick response!

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

No branches or pull requests

4 participants