UNPKG

4.51 kBMarkdownView Raw
1[![Angular](https://user-images.githubusercontent.com/25294569/63955021-b99fca80-ca8c-11e9-9362-1ee8083edd2e.gif)](https://www.apollo-angular.com/)
2
3# [Apollo Angular](https://www.apollo-angular.com/) [![npm version](https://badge.fury.io/js/apollo-angular.svg)](https://badge.fury.io/js/apollo-angular)
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-angular 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- If you are using Apollo-Client v3, please make sure to use `apollo-angular@v3`
38> If you are using Apollo-Client v2, please make sure to use `apollo-angular@v1` (and for Angular 10 support, make sure to use `v1.10.0`)
39
40## Usage
41
42Now you may create components that are connected to your GraphQL API.
43
44Finally, 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:
45
46```ts
47import {Component, OnInit} from '@angular/core';
48import {Apollo, gql} from 'apollo-angular';
49
50const GET_DOGS = gql`
51 {
52 dogs {
53 id
54 breed
55 }
56 }
57`;
58
59@Component({
60 selector: 'dogs',
61 template: `
62 <ul>
63 <li *ngFor="let dog of dogs | async">
64 {{dog.breed}}
65 </li>
66 </ul>
67 `,
68})
69export class DogsComponent implements OnInit {
70 dogs: Observable<any>;
71
72 constructor(private apollo: Apollo) {}
73
74 ngOnInit() {
75 this.dogs = this.apollo
76 .watchQuery({
77 query: GET_DOGS,
78 })
79 .valueChanges.pipe(map(result => result.data && result.data.dogs));
80 }
81}
82```
83
84To learn more about querying with Apollo Angular be sure to start reading the [documentation article on queries](https://apollo-angular.com/docs/data/queries/).
85
86## Documentation
87
88All of the documentation for Apollo Angular including usage articles and helpful recipes lives on: [https://www.apollo-angular.com/](https://www.apollo-angular.com/)
89
90## Contributing
91
92[Read the Apollo Contributor Guidelines.](CONTRIBUTING.md)
93
94This project uses Lerna.
95
96Bootstraping:
97
98```bash
99yarn install
100```
101
102Running tests locally:
103
104```bash
105yarn test
106```
107
108Formatting code with prettier:
109
110```bash
111yarn prettier
112```
113
114This 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.