UNPKG

5.08 kBMarkdownView Raw
1[![Angular](https://user-images.githubusercontent.com/25294569/63955021-b99fca80-ca8c-11e9-9362-1ee8083edd2e.gif)](https://www.apollographql.com/docs/angular/)
2
3# [Apollo Angular](https://www.apollographql.com/docs/angular/) [![npm version](https://badge.fury.io/js/apollo-angular.svg)](https://badge.fury.io/js/apollo-angular) [![Build status](https://travis-ci.org/apollographql/apollo-angular.svg?branch=master)](https://travis-ci.org/apollographql/apollo-angular) [![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/apollo)
4
5Apollo Angular allows you to fetch data from your GraphQL server and use it in building complex and reactive UIs using the Angular framework. Apollo Angular may be used in any context that Angular may be used. In the browser, in NativeScript, or in Node.js when you want to do server-side rendering.
6
7Apollo Angular requires _no_ complex build setup to get up and running. As long as you have a GraphQL server you can get started building out your application with Angular immediately. Apollo Angular works out of the box with both [Angular CLI](https://cli.angular.io/) (`ng add apollo-angular`) and [NativeScript](https://www.nativescript.org/) with a single install.
8
9Apollo Angular is:
10
111. **Incrementally adoptable**, so that you can drop it into an existing JavaScript app and start using GraphQL for just part of your UI.
121. **Universally compatible**, so that Apollo works with any build setup, any GraphQL server, and any GraphQL schema.
131. **Simple to get started with**, so you can start loading data right away and learn about advanced features later.
141. **Inspectable and understandable**, so that you can have great developer tools to understand exactly what is happening in your app.
151. **Built for interactive apps**, so your users can make changes and see them reflected in the UI immediately.
161. **Small and flexible**, so you don't get stuff you don't need. The core is under 12kb compressed.
171. **Community driven**, because Apollo is driven by the community and serves a variety of use cases. Everything is planned and developed in the open.
18
19Get started today on the app you’ve been dreaming of, and let Apollo Angular take you to the moon!
20
21## Installation
22
23It is simple to install Apollo Angular and related libraries
24
25```bash
26# installing Apollo Angular in Angular CLI
27ng add apollo-angular
28
29# installing each piece independently
30yarn add apollo-client apollo-cache-inmemory apollo-angular-link-http apollo-angular graphql-tag graphql
31```
32
33That’s it! You may now use Apollo Angular in any of your Angular environments.
34
35For an amazing developer experience you may also install the [Apollo Client Developer tools for Chrome](https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm) which will give you inspectability into your Apollo Angular data.
36
37## Usage
38
39Now you may create components that are connected to your GraphQL API.
40
41Finally, to demonstrate the power of Apollo Angular in building interactive UIs let us connect one of your components to your GraphQL server using the `Apollo` service:
42
43```ts
44import {Component, OnInit} from '@angular/core';
45import gql from 'graphql-tag';
46import {Apollo} from 'apollo-angular';
47
48const GET_DOGS = gql`
49 {
50 dogs {
51 id
52 breed
53 }
54 }
55`;
56
57@Component({
58 selector: 'dogs',
59 template: `
60 <ul>
61 <li *ngFor="let dog of dogs | async">
62 {{dog.breed}}
63 </li>
64 </ul>
65 `,
66})
67export class DogsComponent implements OnInit {
68 dogs: Observable<any>;
69
70 constructor(private apollo: Apollo) {}
71
72 ngOnInit() {
73 this.dogs = this.apollo
74 .watchQuery({
75 query: GET_DOGS,
76 })
77 .valueChanges.pipe(map(result => result.data && result.data.dogs));
78 }
79}
80```
81
82To learn more about querying with Apollo Angular be sure to start reading the [documentation article on queries](https://www.apollographql.com/docs/angular/basics/queries.html).
83
84## Documentation
85
86All of the documentation for Apollo Angular including usage articles and helpful recipes lives on: [https://www.apollographql.com/docs/angular/](https://www.apollographql.com/docs/angular/)
87
88### Recipes
89
90- [Authentication](https://www.apollographql.com/docs/angular/recipes/authentication.html)
91- [Pagination](https://www.apollographql.com/docs/angular/recipes/pagination.html)
92- [Optimistic UI](https://www.apollographql.com/docs/angular/features/optimistic-ui.html)
93- [Server Side Rendering](https://www.apollographql.com/docs/angular/recipes/server-side-rendering.html)
94
95## Contributing
96
97[Read the Apollo Contributor Guidelines.](CONTRIBUTING.md)
98
99This project uses Lerna.
100
101Bootstraping:
102
103```bash
104yarn install
105```
106
107Running tests locally:
108
109```bash
110yarn test
111```
112
113Formatting code with prettier:
114
115```bash
116yarn prettier
117```
118
119This project uses TypeScript for static typing. You can get it built into your editor with no configuration by opening this project in [Visual Studio Code](https://code.visualstudio.com/), an open source IDE which is available for free on all platforms.