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

@include directive based on variable with default value drops the included data #2690

Closed
klanchman opened this issue Nov 25, 2022 · 2 comments · Fixed by #2794
Closed

@include directive based on variable with default value drops the included data #2690

klanchman opened this issue Nov 25, 2022 · 2 comments · Fixed by #2794
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release

Comments

@klanchman
Copy link
Contributor

Bug report

When using an @include directive, if the variable in the directive has a default value, Apollo drops the included data. I can see the data included in the raw JSON over the network and at lower levels in Apollo, but after Apollo parses it, the data is gone.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.5
  • Xcode version: 14.1
  • Swift version: 5.7.1
  • Package manager: SPM

Steps to reproduce

This problem can be reproduced in the Apollo iOS integration test suite:

  • Create a new query in Sources/StarWarsAPI/starwars-graphql/HeroConditional.graphql:
    query HeroNameConditionalInclusionWithDefault($includeName: Boolean = true) {
      hero {
        id
        name @include(if: $includeName)
      }
    }
  • Run codegen
  • Add a new test in Tests/ApolloServerIntegrationTests/StarWarsServerTests.swift:
      func testDefaultInclude() {
        fetch(query: HeroNameConditionalInclusionWithDefaultQuery(includeName: true)) { data in
          XCTAssertNotNil(data.hero?.id)
          XCTAssertNotNil(data.hero?.name)
        }
      }
  • Start the Star Wars test server
  • Run the new test

Expected result: Test passes.

Actual result: Test fails at the hero name assertion. However, the include directive evaluated to true, and the server returned the data, so the data was lost somewhere.

Further details

Setting anything for the default value of the variable works the same way. Passing in any value also works the same.

Workaround: use a required variable with no default (i.e. Boolean = true => Boolean!)

@calvincestari
Copy link
Member

Thanks for the bug report @klanchman. I'll need to take a deeper look and assess what's going on.

@calvincestari calvincestari self-assigned this Nov 29, 2022
@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation and removed needs investigation labels Jan 3, 2023
@calvincestari calvincestari added this to the Release 1.0.6 milestone Jan 3, 2023
@calvincestari calvincestari added the planned-next Slated to be included in the next release label Jan 5, 2023
@calvincestari
Copy link
Member

@klanchman - this is now fixed and available in main. It'll go out with the next patch (1.0.7) release, sorry this took a while to get done.

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 planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants