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

If there are many duplicate fields across implemented types, is there a way to access them, and get nil if the type does not have the field? #3469

Closed
JOyo246 opened this issue Oct 31, 2024 · 2 comments
Labels
question Issues that have a question which should be addressed

Comments

@JOyo246
Copy link

JOyo246 commented Oct 31, 2024

Question

In our schema, there are cases where there are many polymorphic types that all have the same field, but one type does not have the type, so it is not placed at the top level of the shared type.

Is there any way to access that field by name, if it exists, but get nil if it does not exist?

This is what I'm currently writing which feels super verbose:

extension MyType {
    var someBoolFieldShared: Bool? {
        if let subType1 {
            return subType1.someBoolField
        } else if let subType2 {
            return subType2.someBoolField
        } else if let subType3 {
            return subType3.someBoolField
        } else if let subType4 {
            return subType4.someBoolField
        } else if let subType5 {
            return subType5.someBoolField
        } else if let subType6 {
            return subType6 .someBoolField
        }
        return nil
    }
}
@JOyo246 JOyo246 added the question Issues that have a question which should be addressed label Oct 31, 2024
@calvincestari
Copy link
Member

Hi @JOyo246 - there isn't any way within code generation to automatically have this done for you. The best is what you have now in a custom extension unfortunately.

@calvincestari calvincestari closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2024
Copy link
Contributor

github-actions bot commented Nov 4, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that have a question which should be addressed
Projects
None yet
Development

No branches or pull requests

2 participants