Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-angular

Package Overview
Dependencies
Maintainers
0
Versions
311
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-angular

Use your GraphQL data in your Angular app, with the Apollo Client

  • 8.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
150K
decreased by-1.5%
Maintainers
0
Weekly downloads
 
Created

What is apollo-angular?

The apollo-angular package is a comprehensive Angular integration for Apollo Client, which is a popular GraphQL client. It allows Angular developers to easily query, mutate, and subscribe to data from a GraphQL server, manage local state, and handle caching.

What are apollo-angular's main functionalities?

Querying Data

This feature allows you to query data from a GraphQL server. The code sample demonstrates how to define a GraphQL query, use Apollo's watchQuery method to fetch data, and bind the data to the template using Angular's async pipe.

```typescript
import { Component, OnInit } from '@angular/core';
import { Apollo, gql } from 'apollo-angular';

const GET_DATA = gql`
  query GetData {
    data {
      id
      name
    }
  }
`;

@Component({
  selector: 'app-data',
  template: `
    <div *ngIf="data$ | async as data">
      <div *ngFor="let item of data.data">
        {{ item.name }}
      </div>
    </div>
  `
})
export class DataComponent implements OnInit {
  data$ = this.apollo.watchQuery({ query: GET_DATA }).valueChanges;

  constructor(private apollo: Apollo) {}

  ngOnInit() {}
}
```

Mutating Data

This feature allows you to perform mutations to modify data on the GraphQL server. The code sample shows how to define a mutation, use Apollo's mutate method to send the mutation, and handle the response.

```typescript
import { Component } from '@angular/core';
import { Apollo, gql } from 'apollo-angular';

const ADD_ITEM = gql`
  mutation AddItem($name: String!) {
    addItem(name: $name) {
      id
      name
    }
  }
`;

@Component({
  selector: 'app-add-item',
  template: `
    <input [(ngModel)]="itemName" placeholder="Item name" />
    <button (click)="addItem()">Add Item</button>
  `
})
export class AddItemComponent {
  itemName: string = '';

  constructor(private apollo: Apollo) {}

  addItem() {
    this.apollo.mutate({
      mutation: ADD_ITEM,
      variables: { name: this.itemName }
    }).subscribe(result => {
      console.log('Item added', result);
    });
  }
}
```

Subscription

This feature allows you to subscribe to real-time updates from the GraphQL server. The code sample demonstrates how to define a subscription, use Apollo's subscribe method to listen for updates, and bind the data to the template.

```typescript
import { Component, OnInit } from '@angular/core';
import { Apollo, gql } from 'apollo-angular';

const NEW_ITEM_SUBSCRIPTION = gql`
  subscription OnNewItem {
    newItem {
      id
      name
    }
  }
`;

@Component({
  selector: 'app-new-item',
  template: `
    <div *ngIf="newItem$ | async as newItem">
      New item: {{ newItem.newItem.name }}
    </div>
  `
})
export class NewItemComponent implements OnInit {
  newItem$ = this.apollo.subscribe({ query: NEW_ITEM_SUBSCRIPTION });

  constructor(private apollo: Apollo) {}

  ngOnInit() {}
}
```

Other packages similar to apollo-angular

Keywords

FAQs

Package last updated on 22 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc