diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9269533..1b8bfc507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### vNEXT +- Define types of options and results (of `watchQuery`, `query`, `mutate`) ([PR #145](https://github.com/apollostack/angular2-apollo/pull/145)) + ### v0.7.0 - Added support for **Ahead of Time** compilation ([PR #124](https://github.com/apollostack/angular2-apollo/pull/124)) diff --git a/src/Angular2Apollo.ts b/src/Angular2Apollo.ts index 09b1575b4..b96476840 100644 --- a/src/Angular2Apollo.ts +++ b/src/Angular2Apollo.ts @@ -1,12 +1,23 @@ import { OpaqueToken, Injectable, Inject } from '@angular/core'; import { rxify } from 'apollo-client-rxjs'; -import { ApolloClient, ApolloQueryResult } from 'apollo-client'; +import { ApolloClient, ApolloQueryResult, WatchQueryOptions, MutationBehavior, MutationQueryReducersMap } from 'apollo-client'; import { Observable } from 'rxjs/Observable'; +import { FragmentDefinition } from 'graphql'; import { ApolloQueryObservable } from './ApolloQueryObservable'; import 'rxjs/add/observable/from'; +export interface MutateOptions { + mutation: Document; + variables?: Object; + resultBehaviors?: MutationBehavior[]; + fragments?: FragmentDefinition[]; + optimisticResponse?: Object; + updateQueries?: MutationQueryReducersMap; + refetchQueries?: string[]; +} + export const angularApolloClient = new OpaqueToken('AngularApolloClient'); export function defaultApolloClient(client: ApolloClient): any { return { @@ -21,15 +32,15 @@ export class Angular2Apollo { @Inject(angularApolloClient) private client: any ) {} - public watchQuery(options: any): ApolloQueryObservable { + public watchQuery(options: WatchQueryOptions): ApolloQueryObservable { return new ApolloQueryObservable(rxify(this.client.watchQuery)(options)); } - public query(options: any) { + public query(options: WatchQueryOptions): Promise { return this.client.query(options); } - public mutate(options: any) { + public mutate(options: MutateOptions): Promise { return this.client.mutate(options); }