UNPKG

2.32 kBMarkdownView Raw
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
5An 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
16import { bootstrap } from '@angular/platform-browser-dynamic';
17import { HTTP_PROVIDERS } from '@angular/http';
18import { ApiService, ListService, Config } from 'angular-apollo';
19
20export 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
29bootstrap(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
40import { ionicBootstrap } from 'ionic-angular';
41import { HTTP_PROVIDERS } from '@angular/http';
42import { ApiService, ListService, Config } from 'angular-apollo';
43
44export 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
53ionicBootstrap(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
65You 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```
68export class AppComponent {
69 constructor(tokenStore:TokenStore){
70 tokenStore.events.subscribe(() => {}, () => {
71 redirectToLoginPage();
72 });
73 }
74
75}
76
77```
78
79## Running the tests
80
81Running the E2E tests requires the following environment variables:
82```
83TEST_USER_NAME
84TEST_PASSWORD
85TEST_DEVICE_ID
86TEST_DEVICE_NAME
87TEST_API_URL
88```
89
90Currently all tests are run with the `npm run test` command.
91
\No newline at end of file