Apollo-client: Apollo 3 - optional ApolloQueryResult data is a breaking change - undocumented?

Created on 9 Sep 2020  路  1Comment  路  Source: apollographql/apollo-client

Intended outcome:

Apollo 3 seems to have introduced the undocumented breaking change.

Previously the data field of ApolloQueryResult was not optional, now it is. In the TypeScript environment that forces us to always guard the data to assure it is there. To wrap my mind around it I tried to get undefined from the query but was never successful.

There is no explanation of why it is optional now in neither migration neither in queries document.

My guesses:

  • The change should be documented or changed back to required property.
  • If data is optional only in certain use cases, the type could be split into type with optional and required data property

Actual outcome:

Data is always optional, forcing a lot of if statements or filter operators with rxjs.

Versions

  System:
    OS: macOS 10.15.5
  Binaries:
    Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
    Yarn: 1.22.4 - ~/Projects/censhare-hub/node_modules/.bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.2/bin/npm
  Browsers:
    Chrome: 85.0.4183.83
    Edge: 85.0.564.44
    Firefox: 79.0
    Safari: 13.1.1
  npmPackages:
    @apollo/client: ^3.0.0 => 3.1.4 
    @apollo/link-persisted-queries: ^1.0.0-beta.0 => 1.0.0-beta.0 
    apollo: ^2.30.3 => 2.30.3 
    apollo-angular: ^2.0.4 => 2.0.4

Most helpful comment

This seems to be an (unintended and unnecessary) consequence of 144155c5b16dd36f052d8f7f9401bde51162b8b4, which was part of #6080. Fortunately, removing the ? should not be a breaking change, since it strengthens the type of the data field, strictly reducing the number of possibilities that need to be considered.

>All comments

This seems to be an (unintended and unnecessary) consequence of 144155c5b16dd36f052d8f7f9401bde51162b8b4, which was part of #6080. Fortunately, removing the ? should not be a breaking change, since it strengthens the type of the data field, strictly reducing the number of possibilities that need to be considered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafgraph picture rafgraph  路  3Comments

timbotnik picture timbotnik  路  3Comments

elie222 picture elie222  路  3Comments

stubailo picture stubailo  路  3Comments

MichaelDeBoey picture MichaelDeBoey  路  3Comments