kamilkisiela / apollo-client-rxjs

Adds RxJS to ApolloClient
http://apollostack.com
43 stars 12 forks source link

Fix issues with typescript 2.4.1 & rxjs 5.4.2 and update #44

Closed pfrendo closed 7 years ago

pfrendo commented 7 years ago

This has also been testing with an application running typescript 2.4.1 & rxjs 5.4.2

kamilkisiela commented 7 years ago

Removing a logic from lift method means that now it's not possible to use apollo specific methods after using an operator.

An example:

const obs = new RxObservableQuery(apolloObs)
  .map(({data}) => data.products);

// and later use

obs.refetch();
pfrendo commented 7 years ago

@kamilkisiela, it seems impossible to extend it at it currently stands for some weird reason.

You can still use specific methods but you have to include the type for RxObservableQuery..

As seen in the tests from :

RxObservableQuery<heroes.AllHeroesQueryResult>

you will need to specify the whole type..

RxObservableQuery<ApolloQueryResult<heroes.AllHeroesQueryResult>>

pfrendo commented 7 years ago

@kamilkisiela , can we discuss this please.. As I personally need this :)

picosam commented 7 years ago

Hello, any updates on this? Thanks!

pfrendo commented 7 years ago

@kamilkisiela ... Any update?

kamilkisiela commented 7 years ago

@pfrendo I'll take a look on it tomorrow

beagleknight commented 7 years ago

@kamilkisiela This should solve #36 as well, right?

pfrendo commented 7 years ago

@kamilkisiela ... any update please????

ngocdiep commented 7 years ago

Is it nearly fixed? :)

lukemadera commented 7 years ago

Any update here? Would love to get this in so can use the latest versions again! @kamilkisiela

jjenzz commented 7 years ago

@lukemadera in the meantime do you have a version number I can use that works? This is my first adventure in the Apollo world and I can't seem to get it working 😞

mwld commented 7 years ago

@jjenzz With typescript@2.3.4 it's working fine.

jjenzz commented 7 years ago

@mwld Thank you. I switched version and my app compiled if I set the property type to Observable<any>. However, my editor (vscode) was still complaining:

[ts]
The 'this' context of type 'ApolloQueryObservable<{}>' is not assignable to method's 'this' of type 'Observable<ApolloQueryResult<any>>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<ApolloQueryResult<{}>, ApolloQueryResult<R>>) => Observable<ApolloQueryRes...' is not assignable to type '<R>(operator: Operator<ApolloQueryResult<any>, R>) => Observable<R>'.
      Types of parameters 'operator' and 'operator' are incompatible.
        Type 'Operator<ApolloQueryResult<any>, R>' is not assignable to type 'Operator<ApolloQueryResult<{}>, ApolloQueryResult<{}>>'.
          Type 'R' is not assignable to type 'ApolloQueryResult<{}>'.

image

For anyone else that may have a similar issue, this fixed it for me: https://github.com/angular/angular/issues/17800#issuecomment-315446200

lukemadera commented 7 years ago

@jjenzz what fixed it for you? Reverting typescript to 2.3.4? Or were you able to get it to work with an up to date typescript?

kroeder commented 7 years ago

Can we at least have an approx. date when the fix is going to be released? I'm stuck. apollo-client-rxjs can't use 4.1.0 and another library depends on ^4.1.0

b091 commented 7 years ago

quick walk around

(this.apollo.watchQuery({query, variables, fetchPolicy}) as any).map(({data}) => this.handleResponseData(data)
amitport commented 7 years ago

I've added "skipLibCheck": true, to my tsconfig.app.json as a workaround

volodymyrlut commented 7 years ago

Workaround suggested by @b091 actually works.

KeithGillette commented 7 years ago

Updating to typescript@2.5.2 (and apollo-client@1.9.2) did not produce these errors that I experienced with typescript@2.4.x.

kroeder commented 7 years ago

I can confirm this. typescript@2.4.x + apollo-client@1.9.2 do work now.

What was missing in my code was the generic type for the return value - you might want to check this.

// Pseudo code
myQuery(): ApolloQueryResult<myResultType> {
    // ...
    return this.apollo.query<myResultType>(...)
}

myWatchQuery(): ApolloQueryObservable<myResultType> {
    // ...
    return this.apollo.watchQuery<myResultType>(...)
}

myMutation(): ApolloExecutionResult<myResultType> {
    // ...
    return this.apollo.mutate<myResultType>(...)
}
raysuelzer commented 6 years ago

This issue still occurs: image

"typescript": "~2.5.3" // also failed with 2.4.x and 2.3x "apollo-angular": "^0.13.2", "apollo-client": "^1.9.3",

kroeder commented 6 years ago

Try this one

private getCampaigns(): ApolloQueryObservable<QueryResponse> {
    return this.apollo.watchQuery<QueryResponse>({
        query: query
    });
}

as described in my examples above Does this work?

kamilkisiela commented 6 years ago

If you use apollo-angular then we changed the way ApolloClient works with RxJS. You can check it here: apollographql/apollo-angular#377

No more this kind of issues.