<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Osunkwo</title>
    <description>The latest articles on DEV Community by Daniel Osunkwo (@daxxy).</description>
    <link>https://dev.to/daxxy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1109201%2F61fae36d-bd08-40f8-a027-db2b106de5f7.png</url>
      <title>DEV Community: Daniel Osunkwo</title>
      <link>https://dev.to/daxxy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daxxy"/>
    <language>en</language>
    <item>
      <title>All you need to know about Apollo-Angular Queries</title>
      <dc:creator>Daniel Osunkwo</dc:creator>
      <pubDate>Fri, 19 Jan 2024 07:25:20 +0000</pubDate>
      <link>https://dev.to/daxxy/all-you-need-to-know-about-apollo-angular-queries-5e7g</link>
      <guid>https://dev.to/daxxy/all-you-need-to-know-about-apollo-angular-queries-5e7g</guid>
      <description>&lt;p&gt;Simplifying Data Fetching in Angular Applications&lt;/p&gt;

&lt;p&gt;Introduction:&lt;br&gt;
With Apollo Angular, you can build UI components that fetch data with GraphQL. It is a flexible, community-driven GraphQL client for Angular. You can get the most value out of Apollo Client by integrating it with one of its view layer integrations.&lt;br&gt;
It is designed from the ground up to make it easy to build UI components that fetch data with GraphQL.&lt;/p&gt;

&lt;p&gt;The Angular Toolbox&lt;br&gt;
Apollo is designed to work with all this tools:&lt;br&gt;
Angular Schematics: Apollo Angular supports&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng-add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng-update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NativeScript: Apollo works well out of the box in NativeScript.&lt;br&gt;
Angular Router:&lt;br&gt;
Ionic&lt;/p&gt;

&lt;p&gt;Installation:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The best way to get Apollo Angular is by running this command on your terminal.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng add apollo-angular 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Another thing is to set the URL of your GraphQL Server, open src/app/graphql.module.ts and set uri variables-&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;src/app/graphql.module.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const uri = 'https://48p1r2roz4.sse.codesandbox.io';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also install without using Angular Schematics by using this commands on your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i apollo-angular @apollo/client graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;Queries&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Query simply means retrieving data and or Information from the database&lt;br&gt;
In Apollo Angular we simply need to parse our query into a GraphQL document using the &lt;code&gt;gql&lt;/code&gt; tag from &lt;code&gt;apollo-angular&lt;/code&gt; library using the &lt;code&gt;Apollo.watchQuery&lt;/code&gt; method&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Apollo, gql } from 'apollo-angular';
import { Subscription } from 'rxjs';
import { Component, OnDestroy, OnInit } from '@angular/core';

// We use the gql tag to parse our query string into a query document
const GET_POSTS = gql`
  query GetPosts {
    posts {
      id
      title
    }
  }
`;

@Component({
  // ...
})
class PostsComponent implements OnInit, OnDestroy {
  loading: boolean;
  posts: any;

  private querySubscription: Subscription;

  constructor(private apollo: Apollo) {}

  ngOnInit() {
    this.querySubscription = this.apollo
      .watchQuery&amp;lt;any&amp;gt;({
        query: GET_POSTS,
      })
      .valueChanges.subscribe(({ data, loading }) =&amp;gt; {
        this.loading = loading;
        this.posts = data.posts;
      });
  }

  ngOnDestroy() {
    this.querySubscription.unsubscribe();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result of the &lt;code&gt;watchQuery&lt;/code&gt; method, we get a &lt;code&gt;QueryRef&lt;/code&gt; object with a &lt;code&gt;valueChanges&lt;/code&gt; property.&lt;/p&gt;

</description>
      <category>apollo</category>
      <category>angular</category>
      <category>graphql</category>
      <category>query</category>
    </item>
  </channel>
</rss>
