Skip to content

Commit 180e859

Browse files
authored
Merge pull request #195 from apollostack/aot-2.3.1
Make it AoT 2.3.1+ compatible
2 parents dc47765 + 292e866 commit 180e859

15 files changed

+96
-56
lines changed

.npmignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
.github/
2+
.idea/
3+
.vscode/
24
build/tests/
35
compiled/
46
examples/
57
src/
68
tests/
79
typings/
10+
.bithoundrc
811
.travis.yml
912
.typingsrc
1013
CHANGELOG.md
1114
global.d.ts
12-
karma.conf.js
15+
rollup.conf.js
1316
tsconfig.json
17+
tsconfig.test.json
1418
tslint.json
15-
typings.json
16-
.idea/
17-
.vscode/

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cache:
1111
- $HOME/.npm
1212
- $HOME/.yarn-cache
1313
- node_modules
14+
- examples/hello-world/node_modules
1415

1516
notifications:
1617
# disable email notification
@@ -23,10 +24,15 @@ before_install:
2324
- yarn global add coveralls
2425
# remove unused node modules from cache
2526
- npm prune
27+
- (cd examples/hello-world && npm prune)
2628

27-
install: yarn
29+
install:
30+
- yarn
31+
- (cd examples/hello-world && npm i)
2832

29-
script: yarn test
33+
script:
34+
- yarn test
35+
- (cd examples/hello-world && npm test)
3036

3137
after_script:
3238
# send code-coverage report to coveralls

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### vNEXT
44

55
- Support `es6` modules and `tree-shaking` ([PR #151](https://github.com/apollostack/angular2-apollo/pull/151))
6-
- Make our `Ahead-of-Time` compilation compatible with Angular 2.3.0 ([PR #189](https://github.com/apollostack/angular2-apollo/pull/189))
6+
- Make our `Ahead-of-Time` compilation compatible with Angular 2.3.0 ([PR #189](https://github.com/apollostack/angular2-apollo/pull/189), [PR #195](https://github.com/apollostack/angular2-apollo/pull/195))
77

88
### v0.8.0
99

examples/hello-world/package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66
"scripts": {
77
"preclient": "npm run build",
88
"start": "concurrently \"npm run server\" \"npm run client\"",
9-
"client": "ng serve --proxy-conf proxy.conf.json",
9+
"client": "ng serve --proxy-conf proxy.conf.json --port 4200",
1010
"server": "nodemon api/index.js --watch api --exec babel-node",
1111
"build": "./node_modules/.bin/ngc -p src/tsconfig.aot.json",
12+
"test": "npm run build",
1213
"postbuild": "npm run tree-shaking",
1314
"tree-shaking": "node_modules/.bin/rollup -c rollup.config.js"
1415
},
1516
"private": true,
1617
"dependencies": {
17-
"@angular/common": "~2.1.2",
18-
"@angular/compiler": "~2.1.2",
19-
"@angular/compiler-cli": "~2.1.2",
20-
"@angular/core": "~2.1.2",
21-
"@angular/forms": "~2.1.2",
22-
"@angular/http": "~2.1.2",
23-
"@angular/platform-browser": "~2.1.2",
24-
"@angular/platform-browser-dynamic": "~2.1.2",
25-
"@angular/platform-server": "~2.1.2",
26-
"@angular/router": "~3.1.2",
18+
"@angular/common": "~2.3.1",
19+
"@angular/compiler": "~2.3.1",
20+
"@angular/compiler-cli": "~2.3.1",
21+
"@angular/core": "~2.3.1",
22+
"@angular/forms": "~2.3.1",
23+
"@angular/http": "~2.3.1",
24+
"@angular/platform-browser": "~2.3.1",
25+
"@angular/platform-browser-dynamic": "~2.3.1",
26+
"@angular/platform-server": "~2.3.1",
27+
"@angular/router": "~3.3.1",
2728
"angular2-apollo": "file:../../",
2829
"apollo-client": "~0.5.1",
2930
"core-js": "~2.4.0",
30-
"rxjs": "5.0.0-beta.12",
31+
"rxjs": "5.0.0-rc.4",
3132
"ts-helpers": "~1.1.1",
32-
"zone.js": "~0.6.26"
33+
"zone.js": "~0.7.2"
3334
},
3435
"devDependencies": {
3536
"@types/isomorphic-fetch": "0.0.30",

examples/hello-world/src/app/app.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import { ApolloModule } from 'angular2-apollo';
55

66
import { AppComponent } from './app.component';
7-
import { client } from './client';
7+
import { getClient } from './client';
88

99
@NgModule({
1010
declarations: [
@@ -15,7 +15,7 @@ import { client } from './client';
1515
FormsModule,
1616
ReactiveFormsModule,
1717
// Define the default ApolloClient
18-
ApolloModule.withClient(client),
18+
ApolloModule.withClient(getClient),
1919
],
2020
bootstrap: [AppComponent],
2121
})

examples/hello-world/src/app/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const client = new ApolloClient({
99
}),
1010
});
1111

12-
export {
13-
client
12+
export function getClient(): ApolloClient {
13+
return client;
1414
}

examples/hello-world/src/assets/.gitkeep

Whitespace-only changes.

examples/hello-world/src/tsconfig.aot.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"angularCompilerOptions": {
2525
"genDir": "aot",
26-
"skipMetadataEmit" : true
26+
"skipMetadataEmit" : true,
27+
"entryModule": "app/app.module#AppModule"
2728
}
2829
}

examples/hello-world/src/tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"node",
1818
"isomorphic-fetch"
1919
]
20-
}
20+
},
21+
"files": [
22+
"main.ts"
23+
]
2124
}

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"apollo-client-rxjs": "~0.2.3"
4040
},
4141
"devDependencies": {
42-
"@angular/common": "^2.3.0",
43-
"@angular/compiler": "^2.3.0",
44-
"@angular/compiler-cli": "^2.3.0",
45-
"@angular/core": "^2.3.0",
46-
"@angular/platform-browser": "^2.3.0",
47-
"@angular/platform-browser-dynamic": "^2.3.0",
48-
"@angular/platform-server": "^2.3.0",
42+
"@angular/common": "^2.3.1",
43+
"@angular/compiler": "^2.3.1",
44+
"@angular/compiler-cli": "^2.3.1",
45+
"@angular/core": "^2.3.1",
46+
"@angular/platform-browser": "^2.3.1",
47+
"@angular/platform-browser-dynamic": "^2.3.1",
48+
"@angular/platform-server": "^2.3.1",
4949
"@types/chai": "^3.4.34",
5050
"@types/isomorphic-fetch": "^0.0.30",
5151
"@types/jest": "^15.1.32",

src/Angular2Apollo.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OpaqueToken, Injectable, Inject } from '@angular/core';
22
import { rxify } from 'apollo-client-rxjs';
3-
import { ApolloQueryResult, WatchQueryOptions, MutationOptions, SubscriptionOptions } from 'apollo-client';
3+
import { ApolloClient, ApolloQueryResult, WatchQueryOptions, MutationOptions, SubscriptionOptions } from 'apollo-client';
44
import { Observable } from 'rxjs/Observable';
55
import { FragmentDefinition } from 'graphql';
66

@@ -13,12 +13,13 @@ export interface DeprecatedWatchQueryOptions extends WatchQueryOptions {
1313
fragments?: FragmentDefinition[];
1414
}
1515

16-
export const AngularApolloClient = new OpaqueToken('AngularApolloClient');
16+
export const ApolloClientWrapper = new OpaqueToken('ApolloClientWrapper');
17+
export const ApolloClientInstance = new OpaqueToken('ApolloClientInstance');
1718

1819
@Injectable()
1920
export class Angular2Apollo {
2021
constructor(
21-
@Inject(AngularApolloClient) private client: any,
22+
@Inject(ApolloClientInstance) private client: ApolloClient,
2223
) {}
2324

2425
public watchQuery(options: DeprecatedWatchQueryOptions): ApolloQueryObservable<ApolloQueryResult> {

src/ApolloModule.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule, ModuleWithProviders } from '@angular/core';
22
import { ApolloClient } from 'apollo-client';
33

4-
import { Angular2Apollo, AngularApolloClient } from './Angular2Apollo';
4+
import { Angular2Apollo, ApolloClientWrapper, ApolloClientInstance } from './Angular2Apollo';
55
import { SelectPipe } from './SelectPipe';
66

77
export const APOLLO_DIRECTIVES = [
@@ -11,24 +11,34 @@ export const APOLLO_PROVIDERS = [
1111
Angular2Apollo,
1212
];
1313

14-
export function defaultApolloClient(client: ApolloClient): any {
15-
return {
16-
provide: AngularApolloClient,
17-
useValue: client,
18-
};
14+
export type ClientWrapper = () => ApolloClient;
15+
16+
export function getApolloClient(clientFn: ClientWrapper): ApolloClient {
17+
return clientFn();
18+
}
19+
20+
export function defaultApolloClient(clientFn: ClientWrapper): any {
21+
return [{
22+
provide: ApolloClientWrapper,
23+
useValue: clientFn,
24+
}, {
25+
provide: ApolloClientInstance,
26+
useFactory: getApolloClient,
27+
deps: [ApolloClientWrapper],
28+
}];
1929
}
2030

2131
@NgModule({
2232
declarations: APOLLO_DIRECTIVES,
2333
exports: APOLLO_DIRECTIVES,
2434
})
2535
export class ApolloModule {
26-
public static withClient(client: ApolloClient): ModuleWithProviders {
36+
public static withClient(clientFn: ClientWrapper): ModuleWithProviders {
2737
return {
2838
ngModule: ApolloModule,
2939
providers: [
3040
APOLLO_PROVIDERS,
31-
defaultApolloClient(client),
41+
defaultApolloClient(clientFn),
3242
],
3343
};
3444
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { SelectPipe } from './SelectPipe';
2-
export { Angular2Apollo, AngularApolloClient } from './Angular2Apollo';
2+
export { Angular2Apollo } from './Angular2Apollo';
33
export { ApolloQueryObservable } from './ApolloQueryObservable';
44
export { ApolloModule, APOLLO_PROVIDERS, APOLLO_DIRECTIVES, defaultApolloClient } from './ApolloModule';

tests/Angular2Apollo.spec.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { RxObservableQuery } from 'apollo-client-rxjs';
66

77
import { mockClient } from './_mocks';
88
import { APOLLO_PROVIDERS, defaultApolloClient } from '../src/index';
9-
import { Angular2Apollo, AngularApolloClient } from '../src/Angular2Apollo';
9+
import { Angular2Apollo, ApolloClientWrapper, ApolloClientInstance } from '../src/Angular2Apollo';
1010

1111
import gql from 'graphql-tag';
1212

@@ -66,7 +66,7 @@ describe('angular2Apollo', () => {
6666
let angular2Apollo;
6767

6868
beforeEach(() => {
69-
const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(client), APOLLO_PROVIDERS]);
69+
const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(() => client), APOLLO_PROVIDERS]);
7070
angular2Apollo = injector.get(Angular2Apollo);
7171
});
7272

@@ -245,9 +245,18 @@ describe('angular2Apollo', () => {
245245

246246
describe('defaultApolloClient', () => {
247247

248-
it('should set a AngularApolloClient', () => {
249-
const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(client)]);
250-
expect(injector.get(AngularApolloClient)).toBe(client);
248+
function getClient() {
249+
return client;
250+
}
251+
252+
it('should set a ApolloClientWrapper', () => {
253+
const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(getClient)]);
254+
expect(injector.get(ApolloClientWrapper)).toBe(getClient);
255+
});
256+
257+
it('should set a ApolloClientInstance', () => {
258+
const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(getClient)]);
259+
expect(injector.get(ApolloClientInstance)).toBe(client);
251260
});
252261
});
253262
});

tests/ApolloModule.spec.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ApolloClient } from 'apollo-client';
33
import './_common';
44

55
import { ApolloModule, SelectPipe, Angular2Apollo } from '../src';
6-
import { AngularApolloClient } from '../src/Angular2Apollo';
6+
import { ApolloClientWrapper, ApolloClientInstance } from '../src/Angular2Apollo';
77

88
describe('ApolloModule', () => {
99
let metadata: any = ApolloModule['decorators'][0]['args'][0];
@@ -30,18 +30,26 @@ describe('ApolloModule', () => {
3030

3131
describe('withClient', () => {
3232
const client = {} as ApolloClient;
33-
const result = ApolloModule.withClient(client);
33+
const getClient = () => client;
34+
const result = ApolloModule.withClient(getClient);
35+
const providers = result.providers[1]; // skips APOLLO_PROVIDERS
3436

3537
it('should contain ApolloModule as ngModule', () => {
3638
expect(result.ngModule).toBe(ApolloModule);
3739
});
3840

39-
it('should contain provider with useValue', () => {
40-
expect(result.providers[1]['useValue']).toBe(client);
41+
it('should provide a wrapper directly', () => {
42+
expect(providers[0]['provide']).toBe(ApolloClientWrapper);
43+
expect(providers[0]['useValue']).toBe(getClient);
4144
});
4245

43-
it('should contain provider that provide AngularApolloClient', () => {
44-
expect(result.providers[1]['provide']).toBe(AngularApolloClient);
46+
it('should provide a value using factory', () => {
47+
const factoryResult = providers[1]['useFactory'](getClient);
48+
49+
expect(providers[1]['provide']).toBe(ApolloClientInstance);
50+
expect(providers[1]['useFactory']).toBeDefined();
51+
expect(providers[1]['deps'][0]).toBe(ApolloClientWrapper);
52+
expect(factoryResult).toBe(client);
4553
});
4654
});
4755
});

0 commit comments

Comments
 (0)