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

Generated code cannot compile when using include directive on field that is selected on interface and implementation #3424

Closed
guillian-balisi opened this issue Aug 8, 2024 · 3 comments · Fixed by apollographql/apollo-ios-dev#460
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation

Comments

@guillian-balisi
Copy link

Summary

Apollo is generating some intermediary type If<name_of_boolean_parameter> when selecting fields both on an interface type and an type that implements that interface while using the @include directive. This If<name_of_boolean_parameter> type uses types that are not defined. The generated code does not compile.

Version

1.14.0

Steps to reproduce the behavior

This example is based on the final project of https://github.com/apollographql/iOSTutorial/.

Please download the project on my fork here: https://github.com/guillian-balisi/iOSTutorial/. The differences are in guillian-balisi/iOSTutorial@5075b10, namely:

  1. Added some new types in schema
  2. Added Foo.graphql query
  3. Ran ./apollo-ios-cli generate

If you download the project and open final/RocketReserver.xcodeproj and try to build, it will fail.

Please see the generated code for Foo.graphql: https://github.com/guillian-balisi/iOSTutorial/blob/main/final/RocketReserverAPI/Sources/Operations/Queries/FooQuery.graphql.swift.

Compilation fails because there is the IfIncludeCurrentUserAwards struct with property awardingByCurrentUser of type AwardingByCurrentUser, but type AwardingByCurrentUser does not exist within this namespace.

The workaround we've been using is to move the @include(if: $includeCurrentUserAwards) directive off the awardings field and on to the awardingByCurrentUser field:

query Foo($includeCurrentUserAwards: Boolean = false) {
    postsInfoByIds {
        ... on Post {
            awardings {
                total
            }
        }
        awardings {
            awardingByCurrentUser @include(if: $includeCurrentUserAwards) {   # <---- moved the directive here
                id
            }
        }
    }
}

With that the generated code compiles. But we should expect the generated code to compile regardless of where we use the @include directive.

Logs

No response

Anything else?

No response

@guillian-balisi guillian-balisi added bug Generally incorrect behavior needs investigation labels Aug 8, 2024
@calvincestari
Copy link
Member

Thanks for reporting the issue @guillian-balisi, I'll take a look at the reproduction case and get back to you shortly.

@calvincestari calvincestari self-assigned this Aug 8, 2024
@calvincestari calvincestari added codegen Issues related to or arising from code generation and removed needs investigation labels Aug 9, 2024
@calvincestari
Copy link
Member

Thanks for the reproduction case, I've confirmed it's a valid codegen bug. I'm hoping we can get this into the next release.

Copy link
Contributor

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
bug Generally incorrect behavior codegen Issues related to or arising from code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants