Skip to content

Commit

Permalink
Merge a6d4642 into 2cc3751
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Jan 11, 2017
2 parents 2cc3751 + a6d4642 commit 8788223
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@angular/platform-server": "^2.3.1",
"@angular/router": "^3.3.1",
"angular2-apollo": "file:../../",
"apollo-client": "~0.6.0",
"apollo-client": "~0.7.0",
"core-js": "^2.4.1",
"graphql-tag": "^1.1.2",
"rxjs": "^5.0.1",
Expand Down Expand Up @@ -57,6 +57,6 @@
"rollup-plugin-uglify": "^1.0.1",
"ts-node": "1.2.1",
"tslint": "^4.2.0",
"typescript": "~2.0.6"
"typescript": "~2.1.0"
}
}
2 changes: 1 addition & 1 deletion examples/hello-world/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class AppComponent implements OnInit, AfterViewInit {
},
})
.toPromise()
.then(({ data }: ApolloQueryResult) => {
.then(({ data }: ApolloQueryResult<any>) => {
console.log('got data', data);

// get new data
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
"test-only": "jest",
"test-watch": "jest --watch",
"remap": "remap-istanbul -i coverage/coverage-final.json -t lcovonly -o coverage/lcov.info",
"lint": "tslint src/*.ts && tslint tests/*.ts ",
"lint": "tslint src/*.ts && tslint tests/*.ts",
"build": "./node_modules/.bin/ngc -p tsconfig.json",
"build-test": "./node_modules/.bin/ngc -p tsconfig.test.json",
"postbuild": "npm run bundle",
"bundle": "rollup -c",
"clean": "rimraf build/* coverage/*",
"prepublish": "npm run clean && npm run build",
"prepublishs": "npm run clean && npm run build",
"commitmsg": "validate-commit-msg"
},
"peerDependencies": {
"@angular/core": "^2.0.0",
"apollo-client": "^0.6.0",
"apollo-client": "^0.7.0",
"rxjs": "^5.0.0-beta.12 || ^5.0.0-rc.1 || ^5.0.0"
},
"dependencies": {
"apollo-client-rxjs": "~0.3.0"
"apollo-client-rxjs": "~0.4.0"
},
"devDependencies": {
"@angular/common": "^2.3.1",
Expand All @@ -49,7 +49,8 @@
"@angular/platform-server": "^2.3.1",
"@types/jest": "^15.1.32",
"@types/lodash": "^4.14.34",
"apollo-client": "^0.6.0",
"@types/node": "^6.0.59",
"apollo-client": "^0.7.1",
"graphql": "^0.8.2",
"graphql-tag": "^1.1.2",
"husky": "^0.12.0",
Expand All @@ -60,7 +61,7 @@
"rollup": "^0.39.2",
"rxjs": "^5.0.0",
"tslint": "^4.2.0",
"typescript": "~2.0.6",
"typescript": "~2.1.4",
"validate-commit-msg": "^2.8.2",
"zone.js": "^0.7.1"
},
Expand Down
18 changes: 17 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@ export default {
dest: 'build/bundles/apollo.umd.js',
format: 'umd',
moduleName: 'ng.apollo',
onwarn,
globals: {
'@angular/core': 'ng.core',
'rxjs/Observable': 'Rx'
'rxjs/Observable': 'Rx',
'rxjs/observable/from': 'Rx.Observable',
'rxjs/observable/fromPromise': 'Rx.Observable',
'apollo-client-rxjs': 'apollo.rxjs',
'apollo-client': 'apollo',
}
}

function onwarn(message) {
const suppressed = [
'UNRESOLVED_IMPORT',
'THIS_IS_UNDEFINED'
];

if (!suppressed.find(code => message.code === code)) {
return console.warn(message.message);
}
}
17 changes: 8 additions & 9 deletions src/Angular2Apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { OpaqueToken, Injectable, Inject } from '@angular/core';
import { rxify } from 'apollo-client-rxjs';
import { ApolloClient, ApolloQueryResult, WatchQueryOptions, MutationOptions, SubscriptionOptions } from 'apollo-client';
import { Observable } from 'rxjs/Observable';
import { from } from 'rxjs/observable/from';
import { fromPromise } from 'rxjs/observable/fromPromise';
import { FragmentDefinitionNode } from 'graphql';

import { ApolloQueryObservable } from './ApolloQueryObservable';

import 'rxjs/add/observable/from';
import 'rxjs/add/observable/fromPromise';

export interface DeprecatedWatchQueryOptions extends WatchQueryOptions {
fragments?: FragmentDefinitionNode[];
}
Expand All @@ -22,16 +21,16 @@ export class Angular2Apollo {
@Inject(ApolloClientInstance) private client: ApolloClient,
) {}

public watchQuery(options: DeprecatedWatchQueryOptions): ApolloQueryObservable<ApolloQueryResult> {
public watchQuery<T>(options: DeprecatedWatchQueryOptions): ApolloQueryObservable<ApolloQueryResult<T>> {
return new ApolloQueryObservable(rxify(this.client.watchQuery)(options));
}

public query(options: DeprecatedWatchQueryOptions): Observable<ApolloQueryResult> {
return Observable.fromPromise(this.client.query(options));
public query<T>(options: DeprecatedWatchQueryOptions): Observable<ApolloQueryResult<T>> {
return fromPromise(this.client.query(options));
}

public mutate(options: MutationOptions): Observable<ApolloQueryResult> {
return Observable.fromPromise(this.client.mutate(options));
public mutate<T>(options: MutationOptions): Observable<ApolloQueryResult<T>> {
return fromPromise(this.client.mutate(options));
}

public subscribe(options: SubscriptionOptions): Observable<any> {
Expand All @@ -40,7 +39,7 @@ export class Angular2Apollo {
throw new Error(`Your version of ApolloClient doesn't support subscriptions`);
}

return Observable.from(this.client.subscribe(options));
return from(this.client.subscribe(options));
}

public getClient(): ApolloClient {
Expand Down
3 changes: 2 additions & 1 deletion tests/ApolloModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { ApolloModule, SelectPipe, Angular2Apollo } from '../src';
import { ApolloClientWrapper, ApolloClientInstance } from '../src/Angular2Apollo';

describe('ApolloModule', () => {
let metadata: any = ApolloModule['decorators'][0]['args'][0];
const annotations: any[] = Reflect.getMetadata('annotations', ApolloModule);
const metadata: any = annotations[0]; //ApolloModule['decorators'][0]['args'][0];

it('should contain SelectPipe in declarations', () => {
expect(include(metadata.declarations, SelectPipe)).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion tests/_mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkInterface, BatchedNetworkInterface, Request } from 'apollo-client/transport/networkInterface';
import { NetworkInterface, BatchedNetworkInterface, Request } from 'apollo-client/lib/src/transport/networkInterface';
import { ApolloClient } from 'apollo-client';
import { ExecutionResult, DocumentNode } from 'graphql';
import { print } from 'graphql-tag/printer';
Expand Down

0 comments on commit 8788223

Please sign in to comment.