From c51b27f1b5c0841b714154a6945434ba27b0ee76 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 4 Oct 2016 11:33:04 +0200 Subject: [PATCH] feat: Add Angular2Apollo.subscribe and ApolloQueryObservable.updateQuery --- CHANGELOG.md | 3 +++ package.json | 2 +- src/Angular2Apollo.ts | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 321ed00b4..52f51aad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### vNEXT +- Added `subscribe` method to `Angular2Apollo` service ([PR #113](https://github.com/apollostack/angular2-apollo/pull/113)) +- Added `updateQuery` to `ApolloQueryObservable` ([PR #113](https://github.com/apollostack/angular2-apollo/pull/113)) + ### v0.4.6 - Moved to Angular 2 final and updated RxJS to the latest version ([PR #96](https://github.com/apollostack/angular2-apollo/pull/96)) diff --git a/package.json b/package.json index f01d7a345..f9d66c7e0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "rxjs": "^5.0.0-beta.12" }, "dependencies": { - "apollo-client-rxjs": "^0.0.1", + "apollo-client-rxjs": "^0.1.0", "lodash.assign": "^4.0.9", "lodash.forin": "^4.2.0", "lodash.isequal": "^4.2.0" diff --git a/src/Angular2Apollo.ts b/src/Angular2Apollo.ts index 87b8ccbf4..fa7de0bbd 100644 --- a/src/Angular2Apollo.ts +++ b/src/Angular2Apollo.ts @@ -1,12 +1,13 @@ import { OpaqueToken, Injectable, Inject } from '@angular/core'; import { rxify } from 'apollo-client-rxjs'; import { ApolloQueryResult } from 'apollo-client'; +import { Observable } from 'rxjs/Observable'; import { ApolloQueryObservable } from './ApolloQueryObservable'; import ApolloClient from 'apollo-client'; -import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/observable/from'; export const angularApolloClient = new OpaqueToken('AngularApolloClient'); export const defaultApolloClient = (client: ApolloClient): any => { @@ -22,15 +23,23 @@ export class Angular2Apollo { @Inject(angularApolloClient) private client: any ) {} - public watchQuery(options): ApolloQueryObservable { + public watchQuery(options: any): ApolloQueryObservable { return new ApolloQueryObservable(rxify(this.client.watchQuery)(options)); } - public query(options) { + public query(options: any) { return this.client.query(options); } - public mutate(options) { + public mutate(options: any) { return this.client.mutate(options); } + + public subscribe(options: any): Observable { + if (typeof this.client.subscribe === 'undefined') { + throw new Error(`Your version of ApolloClient doesn't support subscriptions`); + } + + return Observable.from(this.client.subscribe(options)); + } }