Description
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!
)
Activity