Skip to content

Commit

Permalink
Add result(), currentResult(), variables, setOptions, `setVar…
Browse files Browse the repository at this point in the history
…iables` (#29)
  • Loading branch information
kamilkisiela authored Feb 4, 2017
1 parent 3b494a7 commit 8a39d4b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### vNEXT

- Add `result()`, `currentResult()`, `variables`, `setOptions`, `setVariables` [PR #29](https://github.com/kamilkisiela/apollo-client-rxjs/pull/29)

### v0.4.1

Expand Down
21 changes: 21 additions & 0 deletions src/RxObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ export class RxObservableQuery<T> extends Observable<T> {
return this.getObservableQuery().subscribeToMore(options);
}

public result(): Promise<ApolloQueryResult<any>> {
return this.getObservableQuery().result();
}

public currentResult(): ApolloQueryResult<any> {
return this.getObservableQuery().currentResult();
}

public get variables(): any {
return this.getObservableQuery().variables;
}

// XXX set ModifiableWatchQueryOptions as an interface of opts
public setOptions(opts: any): Promise<ApolloQueryResult<any>> {
return this.getObservableQuery().setOptions(opts);
}

public setVariables(variables: any, tryFetch: boolean = false): Promise<ApolloQueryResult<any>> {
return this.getObservableQuery().setVariables(variables, tryFetch);
}

// where magic happens

public _subscribe(subscriber: Subscriber<T>) {
Expand Down
36 changes: 36 additions & 0 deletions tests/RxObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,41 @@ describe('RxObservableQuery', () => {
assert.deepEqual(stubbed.args[0], [mapFn]);
assert.equal(result, undefined);
});

it('should be able to use result', () => {
stub(obsQuery, 'result').returns('promise');
const promise = rxObsQuery.result();

assert.equal(promise, 'promise');
});

it('should be able to use currentResult', () => {
stub(obsQuery, 'currentResult').returns('ApolloQueryResult');
const result = rxObsQuery.currentResult();

assert.equal(result, 'ApolloQueryResult');
});

it('should be able to get variables', () => {
assert.isTrue(rxObsQuery.variables === obsQuery.variables);
});

it('should be able to setOptions', () => {
const stubbed = stub(obsQuery, 'setOptions').returns('promise');
const options = {};
const promise = rxObsQuery.setOptions(options);

assert.deepEqual(stubbed.args[0], [options]);
assert.equal(promise, 'promise');
});

it('should be able to setVariables', () => {
const stubbed = stub(obsQuery, 'setVariables').returns('promise');
const variables = {};
const promise = rxObsQuery.setVariables(variables);

assert.deepEqual(stubbed.args[0], [variables, false]);
assert.equal(promise, 'promise');
});
});
});

0 comments on commit 8a39d4b

Please sign in to comment.