kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 309 forks source link

Types of property 'fetchPolicy' are incompatible. #1785

Closed bogomips closed 1 year ago

bogomips commented 2 years ago

Describe the bug

I get a compilation error if I use the option fetchPolicy.

To Reproduce

if I have a query that looks like this

const query = {
      query: myQuery,      
      variables: {
        id: id,
        date: date
      },
      fetchPolicy: 'no-cache'
    }

    this.apollo.query(query);

I get

Types of property 'fetchPolicy' are incompatible.
Type 'string' is not assignable to type 'FetchPolicy'.

Expected behavior

adding the fetchPolicy option should not generate an error

Environment:

├── @angular/cli@13.3.5 
├── @apollo/client@3.6.2 
├── apollo-angular@3.0.1 
├── graphql@15.8.0 
└── typescript@4.5.5 

Additional context

I temporarily solved this way:

I've copied the following line from the TS definition and added in my ts file

export declare type FetchPolicy = 'cache-first' | 'network-only' | 'cache-only' | 'no-cache' | 'standby'; // trying to fix a TS issue

Then run the query this way

    const noCache:FetchPolicy = "no-cache"; //trick to fix it the TS error

    const query = {
      query: myQuery,      
      variables: {
        id: id,
        date: date
      },
      fetchPolicy: noCache
    }

    this.apollo.query(query);