1 | # Angular apollo
|
2 |
|
3 | [![npm version](https://badge.fury.io/js/angular-apollo.svg)](https://badge.fury.io/js/angular-apollo) [![CircleCI](https://circleci.com/gh/7digital/angular-apollo.svg?style=svg&circle-token=be7bccdd854c7e6852ae1da2140e9899f83003dd)](https://circleci.com/gh/7digital/angular-apollo)
|
4 |
|
5 | An API client for the 7digital Apollo platform built for Angular 2 projects.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | `npm install angular-apollo`
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ### For a web project:
|
14 |
|
15 | ```typescript
|
16 | import { bootstrap } from '@angular/platform-browser-dynamic';
|
17 | import { HTTP_PROVIDERS } from '@angular/http';
|
18 | import { ApiService, ListService, Config } from 'angular-apollo';
|
19 |
|
20 | export class AppComponent {
|
21 | constructor(private playlistService:ListService){
|
22 | return this.playlistService.findById(10)
|
23 | .subscribe((playlist) => {
|
24 | this.apolloId = playlist.id;
|
25 | }) ;
|
26 | };
|
27 | }
|
28 |
|
29 | bootstrap(AppComponent, [
|
30 | HTTP_PROVIDERS,
|
31 | provideApollo({
|
32 | baseUrl: 'http://www.example.com'
|
33 | })
|
34 | ]);
|
35 | ```
|
36 |
|
37 | ### For an ionic2 project you will need to override the token store:
|
38 |
|
39 | ```typescript
|
40 | import { ionicBootstrap } from 'ionic-angular';
|
41 | import { HTTP_PROVIDERS } from '@angular/http';
|
42 | import { ApiService, ListService, Config } from 'angular-apollo';
|
43 |
|
44 | export class AppComponent {
|
45 | constructor(private playlistService:ListService){
|
46 | return this.playlistService.findById(10)
|
47 | .subscribe((playlist) => {
|
48 | this.apolloId = playlist.id;
|
49 | }) ;
|
50 | };
|
51 | }
|
52 |
|
53 | ionicBootstrap(AppComponent, [
|
54 | provideApollo({
|
55 | baseUrl: 'http://www.example.com',
|
56 | useTokenStore: () => (
|
57 | {provide: TokenStore, useClass: YourCustomTokenStore}
|
58 | )
|
59 | })
|
60 | ]);
|
61 | ```
|
62 |
|
63 | ### Handling authentication errors
|
64 |
|
65 | You may want your app to react to failed authentication attempts, in this case, you can register a handler for the token store errors
|
66 |
|
67 | ```
|
68 | export class AppComponent {
|
69 | constructor(tokenStore:TokenStore){
|
70 | tokenStore.events.subscribe(() => {}, () => {
|
71 | redirectToLoginPage();
|
72 | });
|
73 | }
|
74 |
|
75 | }
|
76 |
|
77 | ```
|
78 |
|
79 | ## Running the tests
|
80 |
|
81 | Running the E2E tests requires the following environment variables:
|
82 | ```
|
83 | TEST_USER_NAME
|
84 | TEST_PASSWORD
|
85 | TEST_DEVICE_ID
|
86 | TEST_DEVICE_NAME
|
87 | TEST_API_URL
|
88 | ```
|
89 |
|
90 | Currently all tests are run with the `npm run test` command.
|
91 |
|
\ | No newline at end of file |