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

unable to compile with TS as of 2.6.0 #4851

Closed
blackmagic0 opened this issue May 22, 2019 · 2 comments
Closed

unable to compile with TS as of 2.6.0 #4851

blackmagic0 opened this issue May 22, 2019 · 2 comments

Comments

@blackmagic0
Copy link

Intended outcome:

React app using apollo-boost version 0.3.1 depends on apollo-client version ^2.5.1 fails to compile with typescript version 3.4.5 with error, notable react-apollo is also locked to version 2.5.2 as any newer version fails to pass client through HOC's:
Type '"cache-and-network"' is not assignable to type '"cache-first" | "network-only" | "cache-only" | "no-cache" | "standby" | undefined'. TS2322

<Query query={query} variables={var} fetchPolicy={"cache-and-network"}>

This is with a fresh package-lock.json, cleared node_modules and npm cache cleared followed by an npm install

Actual outcome:

React app using apollo-boost version 0.3.1 depends on apollo-client version ^2.5.1 fails to compile with typescript version 3.4.5 with error:
Type '"cache-and-network"' is not assignable to type '"cache-first" | "network-only" | "cache-only" | "no-cache" | "standby" | undefined'. TS2322

<Query query={query} variables={var} fetchPolicy={"cache-and-network"}>

This is with a fresh package-lock.json, cleared node_modules and npm cache cleared followed by an npm install

apollo-client version 2.6.0 is installed and the App fails to run with the error described above.

this appears to be some change in apollo-client/core/watchQueryOptions.ts from version 2.5.1:
export declare type FetchPolicy = 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only' | 'no-cache' | 'standby';

changed to in version 2.6.0:
export type FetchPolicy = 'cache-first' | 'network-only' | 'cache-only' | 'no-cache' | 'standby'; export type WatchQueryFetchPolicy = FetchPolicy | 'cache-and-network';

How to reproduce the issue:

create a react app with typescript version 3.4.5 and apollo-boost 0.3.1 or apollo-client 2.6.0 and use a query component with the fetch policy "cache-and-network"

Versions

System:
OS: Windows 10
Binaries:
Node: 8.11.3 - C:\Program Files\nodejs\node.EXE
npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0
npmPackages:
apollo-boost: ^0.3.1 => 0.3.1
apollo-client: 2.5.1 => 2.5.1
react-apollo: 2.5.2 => 2.5.6

@benjamn
Copy link
Member

benjamn commented May 22, 2019

This was an intentional change in Apollo Client 2.6.0, discussed in #3130, and documented in CHANGELOG.md:

  • The FetchPolicy type has been split into two types, so that passing cache-and-network to ApolloClient#query is now forbidden at the type level, whereas previously it was forbidden by a runtime invariant assertion:
    export type FetchPolicy =
      | 'cache-first'
      | 'network-only'
      | 'cache-only'
      | 'no-cache'
      | 'standby';
    
    export type WatchQueryFetchPolicy =
      | FetchPolicy
      | 'cache-and-network';
    The exception thrown if you ignore the type error has also been improved to explain the motivation behind this restriction.

    Issue #3130 (comment) and commit cf069bc7

Note: it's important to use react-apollo@2.5.6 together with apollo-client@2.6.0. Not sure if it's a typo that your apollo-client version is still 2.5.1?

@blackmagic0
Copy link
Author

ok, thanks for the clarification!

@benjamn benjamn removed the 🏓 awaiting-contributor-response requires input from a contributor label May 22, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants