<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Asmita Pawar on Medium]]></title>
        <description><![CDATA[Stories by Asmita Pawar on Medium]]></description>
        <link>https://medium.com/@aapawar?source=rss-dfcde80026c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_B6pCevlo96sW1QB</url>
            <title>Stories by Asmita Pawar on Medium</title>
            <link>https://medium.com/@aapawar?source=rss-dfcde80026c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:01:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aapawar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Comprehensive Guide to AWS Cognito in Angular using AWS Amplify]]></title>
            <link>https://medium.com/@aapawar/comprehensive-guide-to-aws-cognito-in-angular-using-aws-amplify-fd394d212133?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd394d212133</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cognito]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[amplify]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 11:50:33 GMT</pubDate>
            <atom:updated>2023-06-04T11:50:33.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*2GSQsA8KxKiqKF1RE5sFNQ.jpeg" /></figure><h3>Introduction:</h3><p>In modern web applications, user authentication and authorization play a vital role in ensuring security and protecting user data. AWS Cognito, a fully managed user authentication service, provides a seamless solution for user management in your Angular applications. When combined with AWS Amplify, a JavaScript library, the process becomes even more streamlined. In this blog, we will explore how to integrate AWS Cognito into an Angular application using AWS Amplify, providing a detailed explanation of the code involved.</p><h3>Prerequisites:</h3><p>Before diving into the implementation, make sure you have the following prerequisites in place:</p><ol><li>Basic knowledge of Angular and TypeScript.</li><li>An AWS account with the necessary permissions to create and configure AWS Cognito resources.</li><li>Node.js and npm installed on your machine.</li></ol><h4>Step 1:</h4><p>Set up an Angular Project To begin, let’s set up a new Angular project using the Angular CLI. Open your terminal and run the following command:</p><pre>ng new aws-cognito-angular</pre><p>Navigate into the project directory:</p><pre>cd aws-cognito-angular</pre><h4>Step 2:</h4><p>Install AWS Amplify Next, we need to install the AWS Amplify library to handle the integration with AWS Cognito. Run the following command:</p><pre>npm install aws-amplify @aws-amplify/ui-angular</pre><h4>Step 3:</h4><p>Configure AWS Amplify To configure AWS Amplify, we need to run the configuration command and provide the necessary details. In the terminal, run:</p><pre>npx amplify configure</pre><p>Follow the prompts to sign in to your AWS account and configure the AWS Amplify CLI.</p><h4>Step 4:</h4><p>Create an AWS Cognito User Pool Now, let’s create an AWS Cognito User Pool. In the terminal, run:</p><pre>npx amplify init</pre><p>Follow the prompts and choose the options that suit your project requirements. Once the initialization is complete, run:</p><pre>npx amplify add auth</pre><p>Again, follow the prompts to configure your user pool.</p><h4>Step 5:</h4><p>Generate AWS Amplify Code AWS Amplify provides a code generation feature that generates the necessary code for working with AWS Cognito. Run the following command in the terminal:</p><pre>npx amplify codegen add</pre><p>Select the option to generate code for the authentication category and choose “Yes” when prompted to update your GraphQL schema.</p><h4>Step 6:</h4><p>Import AWS Amplify Modules In your Angular application, open the app.module.ts file and import the necessary AWS Amplify modules. Add the following imports at the top of the file:</p><pre>import Amplify from &#39;aws-amplify&#39;;<br>import { AmplifyUIAngularModule } from &#39;@aws-amplify/ui-angular&#39;;</pre><h4>Step 7:</h4><p>Initialize AWS Amplify To initialize AWS Amplify, add the following code to the ngOnInit() method of your AppComponent:</p><pre>ngOnInit(): void {<br>  Amplify.configure({<br>    Auth: {<br>      identityPoolId: &#39;&lt;YOUR_IDENTITY_POOL_ID&gt;&#39;,<br>      region: &#39;&lt;YOUR_AWS_REGION&gt;&#39;,<br>      userPoolId: &#39;&lt;YOUR_USER_POOL_ID&gt;&#39;,<br>      userPoolWebClientId: &#39;&lt;YOUR_USER_POOL_WEB_CLIENT_ID&gt;&#39;,<br>    },<br>  });<br>}</pre><p>Replace the placeholders with your actual Cognito user pool details.</p><h4>Step 8:</h4><p>Use AWS Amplify UI Components Now, we can leverage the AWS Amplify UI components for authentication in our Angular templates. Open the app.component.html file and add the following code:</p><pre>&lt;amplify-authenticator&gt;<br>  &lt;amplify-sign-in&gt;&lt;/amplify-sign-in&gt;<br>  &lt;amplify-sign-up&gt;&lt;/amplify-sign-up&gt;<br>  &lt;amplify-sign-out&gt;&lt;/amplify-sign-out&gt;<br>&lt;/amplify-authenticator&gt;</pre><h4>Step 9:</h4><p>Start the Angular Development Server Finally, let’s start the Angular development server to see our authentication flow in action. Run the following command:</p><pre>ng serve</pre><p>Navigate to http://localhost:4200 in your browser, and you should see the AWS Cognito authentication UI.</p><h3>Conclusion:</h3><p>In this blog, we have explored how to integrate AWS Cognito into an Angular application using AWS Amplify. We covered the step-by-step process, from setting up an Angular project to configuring AWS Cognito and leveraging AWS Amplify’s code generation and UI components. By following these steps, you can easily incorporate secure user authentication and authorization into your Angular applications.</p><h3>References:</h3><ol><li>AWS Amplify Documentation: <a href="https://docs.amplify.aws/">https://docs.amplify.aws/</a></li><li>Angular Documentation: <a href="https://angular.io/">https://angular.io/</a></li><li>AWS Cognito Documentation: <a href="https://aws.amazon.com/cognito/">https://aws.amazon.com/cognito/</a></li><li>AWS Amplify GitHub Repository: <a href="https://github.com/aws-amplify/amplify-js">https://github.com/aws-amplify/amplify-js</a></li></ol><p>Please note that the above references are subject to change. It’s always recommended to refer to the official documentation for the most up-to-date information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd394d212133" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Basic To-Do Application with Angular]]></title>
            <link>https://medium.com/@aapawar/building-a-basic-to-do-application-with-angular-8cf7e5d69bd8?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cf7e5d69bd8</guid>
            <category><![CDATA[angular-app-development]]></category>
            <category><![CDATA[application]]></category>
            <category><![CDATA[to-do-list]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Wed, 17 May 2023 07:16:48 GMT</pubDate>
            <atom:updated>2023-05-17T07:16:48.548Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Step-by-Step Guide</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*7MDBO4C1pa1v3Mn653tfSg.jpeg" /></figure><h4><strong>Introduction:</strong></h4><p>In this tutorial, we will dive into the process of creating a basic to-do application using Angular. Angular is a popular JavaScript framework that allows us to build dynamic web applications with ease. By following this step-by-step guide, you will learn how to set up an Angular project, create components, implement data binding, and handle user interactions. So, let’s get started!</p><h4><strong>Prerequisites:</strong></h4><p>Before we begin, make sure you have the following installed on your system:</p><ol><li>Node.js and npm (Node Package Manager)</li><li>Angular CLI (Command Line Interface)</li></ol><h4><strong>Step 1:</strong> <strong>Setting up the Angular Project</strong></h4><p>To create an Angular project, open your terminal or command prompt and execute the following command:</p><pre>ng new todo-app</pre><p>This will create a new Angular project named “todo-app” in a directory with the same name. Once the command finishes execution, navigate into the project directory using:</p><pre>cd todo-app</pre><h4><strong>Step 2:</strong> <strong>Creating Components</strong></h4><p>In Angular, components are the building blocks of an application. Let’s create two components for our to-do application: todo-list and todo-item. Execute the following commands in the terminal:</p><pre>ng generate component todo-list<br>ng generate component todo-item</pre><p>This will generate the required files and folders for each component inside the src/app directory.</p><h4><strong>Step 3:</strong> <strong>Designing the User Interface</strong></h4><p>Open the todo-list.component.html file and replace its content with the following code:</p><pre>&lt;h1&gt;Todo List&lt;/h1&gt;<br>&lt;input type=&quot;text&quot; [(ngModel)]=&quot;newTodo&quot; placeholder=&quot;Add a new todo&quot;&gt;<br>&lt;button (click)=&quot;addTodo()&quot;&gt;Add&lt;/button&gt;<br>&lt;ul&gt;<br>  &lt;li *ngFor=&quot;let todo of todos&quot;&gt;{{ todo }}&lt;/li&gt;<br>&lt;/ul&gt;</pre><h4><strong>Step 4:</strong> <strong>Implementing Component Logic</strong></h4><p>Open the todo-list.component.ts file and replace its content with the following code:</p><pre>import { Component } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-todo-list&#39;,<br>  templateUrl: &#39;./todo-list.component.html&#39;,<br>  styleUrls: [&#39;./todo-list.component.css&#39;]<br>})<br>export class TodoListComponent {<br>  todos: string[] = [];<br>  newTodo: string = &#39;&#39;;<br><br>  addTodo() {<br>    if (this.newTodo !== &#39;&#39;) {<br>      this.todos.push(this.newTodo);<br>      this.newTodo = &#39;&#39;;<br>    }<br>  }<br>}</pre><h4><strong>Step 5: Styling the Components</strong></h4><p>Create a new file named todo-list.component.css and add the following code:</p><pre>ul {<br>  list-style-type: none;<br>  padding: 0;<br>}<br><br>li {<br>  margin-bottom: 10px;<br>}</pre><h4><strong>Step 6: Adding the Components to the App</strong></h4><p>Open the app.component.html file and replace its content with the following code:</p><pre>&lt;app-todo-list&gt;&lt;/app-todo-list&gt;</pre><h4><strong>Step 7: Running the Application</strong></h4><p>To run the application, execute the following command in the terminal:</p><pre>ng serve</pre><p>Once the build process is complete, you can access the to-do application by opening your browser and navigating to <a href="http://localhost:4200.">http://localhost:4200.</a></p><h3><strong>Conclusion:</strong></h3><p>Congratulations! You have successfully built a basic to-do application using Angular. Throughout this tutorial, we covered the steps involved in creating an Angular project, generating components, implementing component logic, and styling the components. Feel free to explore further by adding more features and enhancing the user interface. Happy coding!</p><p>Remember, this tutorial only scratches the surface of what Angular can do. To delve deeper into Angular development, consult the official Angular documentation and explore more advanced concepts and features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cf7e5d69bd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Observables is Angular]]></title>
            <link>https://medium.com/@aapawar/observables-is-angular-c57a7ef96251?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c57a7ef96251</guid>
            <category><![CDATA[subscribers]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[observables]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 11:29:51 GMT</pubDate>
            <atom:updated>2023-04-28T11:29:51.483Z</atom:updated>
            <content:encoded><![CDATA[<h4>Handling Asynchronous data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*N7NqCftzIMTNfVDvb5syvA.png" /></figure><h4>Introduction</h4><p>Observables are a powerful tool for managing asynchronous data streams in Angular. They are based on the concept of reactive programming, which emphasizes the propagation of changes throughout a system. In Angular, observables are used extensively for managing asynchronous data streams, such as HTTP requests, user input, and event streams.</p><p>In this article, we will provide a theoretical overview of observables in Angular and how they relate to reactive programming. We will also provide an example usage of observables in Angular, illustrating how to display a loading spinner while an HTTP request is being made, and then display the list of items once the request is complete.</p><h4>Theoretical Overview</h4><p>At its core, an observable is a representation of a stream of data that can be subscribed to. The stream can emit values at any time, and subscribers to the stream can receive and react to those values as they arrive.</p><p>The observable pattern is based on the concept of reactive programming, which is a programming paradigm that emphasizes the propagation of changes throughout a system. In reactive programming, data flows through a series of functions or components, with each step in the process reacting to changes in the data and producing new data that can be passed on to the next step.</p><p>Observables in Angular are based on the ReactiveX library, which is a cross-platform implementation of the reactive programming pattern. ReactiveX provides a consistent set of APIs for working with asynchronous data streams across multiple languages and platforms.</p><p>In Angular, observables are used extensively for managing asynchronous data streams, such as HTTP requests, user input, and event streams. By using observables, developers can write code that is more concise, more modular, and easier to reason about.</p><h4>Example Usage</h4><p>To illustrate the use of observables in Angular, let’s consider a simple example. Suppose we have a component that displays a list of items retrieved from a server using an HTTP request. We want to display a loading spinner while the request is being made, and then display the list of items once the request is complete.</p><p>To achieve this, we can create an observable that represents the HTTP request, and then subscribe to it in our component. The observable will emit three types of events: a “start” event when the request is initiated, a “success” event when the request is complete and successful, and an “error” event if the request fails.</p><p>Here’s what the code might look like:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { HttpClient } from &#39;@angular/common/http&#39;;<br>import { Observable } from &#39;rxjs&#39;;<br><br>@Component({<br>  selector: &#39;app-item-list&#39;,<br>  template: `<br>    &lt;div *ngIf=&quot;loading&quot;&gt;<br>      Loading...<br>    &lt;/div&gt;<br>    &lt;ul *ngIf=&quot;!loading&quot;&gt;<br>      &lt;li *ngFor=&quot;let item of items&quot;&gt;{{item.name}}&lt;/li&gt;<br>    &lt;/ul&gt;<br>  `<br>})<br>export class ItemListComponent {<br>  loading = true;<br>  items: any[];<br><br>  constructor(private http: HttpClient) {}<br><br>  ngOnInit() {<br>    const url = &#39;https://my-api.com/items&#39;;<br>    const observable = this.http.get(url);<br><br>    observable.subscribe(<br>      (data) =&gt; {<br>        this.items = data;<br>        this.loading = false;<br>      },<br>      (error) =&gt; {<br>        console.error(error);<br>        this.loading = false;<br>      }<br>    );<br>  }<br>}</pre><p>In this code, we create an HTTP request observable by calling this.http.get(url). We then subscribe to the observable using the subscribe method, which takes two arguments: a callback function to handle successful responses ((data) =&gt; {...}) and a callback function to handle errors ((error) =&gt; {...}). In the successful response callback, we update the items array with the data returned by the server, and set loading to false once the data has been received. In the error callback, we log the error to the console and also set loading to false.</p><p>Note that we have used the *ngIf directive to conditionally display either the loading spinner or the list of items, based on the value of the loading property. We have also used the *ngFor directive to iterate over the items array and display each item in the list.</p><h4>Best Practices</h4><p>Observables in Angular are a powerful tool, but they can also be complex and difficult to understand for developers who are new to reactive programming. However, by mastering the concept of observables, developers can write code that is more concise, more modular, and easier to reason about.</p><p>Here are some best practices to keep in mind when working with observables in Angular:</p><ol><li>Always unsubscribe from observables when they are no longer needed. This can be done using the unsubscribe method on the subscription object returned by the subscribe method. Failing to unsubscribe can lead to memory leaks and unexpected behavior.</li><li>Use the async pipe in Angular templates to avoid manual subscription and unsubscription. The async pipe takes care of subscribing and unsubscribing automatically. This can help simplify your code and reduce the risk of memory leaks.</li><li>Use operators from the RxJS library to manipulate observable data streams. Operators can be used to filter, map, reduce, and transform data streams in a variety of ways. By using operators, you can write more expressive and concise code.</li><li>Avoid creating new observables unnecessarily. Instead, try to reuse existing observables as much as possible. This can help reduce the complexity of your code and improve performance.</li><li>Use the catchError operator to handle errors in observable data streams. This operator allows you to handle errors in a centralized and consistent way, rather than handling them in individual callbacks.</li></ol><h4>Conclusion</h4><p>Observables are a powerful tool for managing asynchronous data streams in Angular. They are based on the concept of reactive programming, which emphasizes the propagation of changes throughout a system. In Angular, observables are used extensively for managing asynchronous data streams, such as HTTP requests, user input, and event streams.</p><p>In this article, we have provided a theoretical overview of observables in Angular and how they relate to reactive programming. We have also provided an example usage of observables in Angular, illustrating how to display a loading spinner while an HTTP request is being made, and then display the list of items once the request is complete.</p><p>Observables in Angular are a powerful tool, but they can also be complex and difficult to understand for developers who are new to reactive programming. However, by following best practices and mastering the concept of observables, developers can write code that is more concise, more modular, and easier to reason about.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c57a7ef96251" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Components and Templates in Angular]]></title>
            <link>https://medium.com/@aapawar/components-and-templates-in-angular-fd73e0674340?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd73e0674340</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[template]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 06:52:58 GMT</pubDate>
            <atom:updated>2023-04-17T06:52:58.562Z</atom:updated>
            <content:encoded><![CDATA[<h4>The basic building blocks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJ0UD-GtudJasgDxMmXhYA.png" /></figure><p>Angular is a powerful and popular JavaScript framework for building modern web applications. It uses a component-based architecture to break down complex applications into smaller, reusable parts, making it easier to develop, test, and maintain large codebases. In this blog, we will take a closer look at components and templates in Angular, and dive into the @Component() decorator, a key element in the Angular framework.</p><h4>What are Components in Angular?</h4><p>Components in Angular are self-contained, reusable building blocks that define the behavior and presentation of a specific part of a web page. They are a key element in the Angular architecture, and they allow developers to create complex web applications by breaking them down into smaller, easier-to-manage parts.</p><p>A component in Angular is made up of three parts:</p><ol><li><strong>Component Class:</strong> This is a TypeScript class that defines the logic and properties of the component.</li><li><strong>Template: </strong>This is an HTML file that defines the structure and content of the component.</li><li><strong>Style Sheet:</strong> This is a CSS file that defines the styles for the component.</li></ol><h4>Creating a Component in Angular</h4><p>Angular provides a command-line interface (CLI) tool that makes it easy to create new components. To create a new component, simply run the following command in the terminal:</p><pre>ng generate component component-name</pre><p>This will create a new directory with the name of the component, and inside that directory, there will be three files: component-name.component.ts, component-name.component.html, and component-name.component.css.</p><p>After the component is created, you can edit the component class, template, and style sheet to define the behavior and presentation of the component.</p><h4>The @Component() Decorator</h4><p>The @Component() decorator is a TypeScript decorator that is used to mark a TypeScript class as an Angular component. The decorator provides metadata that Angular needs to create and manage the component.</p><p>The @Component() decorator takes an object as a parameter that defines the metadata for the component. Some of the properties that can be defined in the @Component() decorator include:</p><ul><li><strong>selector:</strong> This is a required property that defines the HTML tag that will be used to render the component.</li><li><strong>templateUrl:</strong> This property defines the URL of the HTML template file that will be used to render the component.</li><li><strong>styleUrls: </strong>This property defines an array of URLs for the CSS style sheets that will be used for the component.</li><li><strong>providers:</strong> This property defines an array of services that the component will use.</li><li><strong>animations: </strong>This property defines an array of animation objects that will be used for the component.</li><li><strong>encapsulation:</strong> This property defines the style encapsulation strategy for the component. The three possible values are Emulated, Native, and None.</li><li><strong>changeDetection:</strong> This property defines the change detection strategy for the component. The two possible values are Default and OnPush.</li></ul><p>The @Component() decorator can be used to define a component in a TypeScript class. Here is an example of a simple component:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>@Component({<br>  selector: &#39;app-example&#39;,<br>  templateUrl: &#39;./example.component.html&#39;,<br>  styleUrls: [&#39;./example.component.css&#39;]<br>})<br>export class ExampleComponent {<br>  pageTitle = &#39;Example Page&#39;;<br>}</pre><p>In this example, the @Component() decorator is used to define a component class called ExampleComponent. The component has a selector of ‘app-example’, a template URL of ‘./example.component.html’, and a style URL of ‘./example.component.css’. The class also defines a pageTitle property that is used in the template.</p><h4>Templates in Angular</h4><p>Templates in Angular are HTML files that define the structure and content of a component. They allow developers to separate the presentation layer from the business logic layer, making it easier to maintain and test code.</p><p>Angular templates use a special syntax that allows the template to interact with the component class. This syntax includes interpolation, property binding, event binding, and structural directives.</p><p><strong>Interpolation</strong></p><p>Interpolation is a way to display data from the component class in the template. Interpolation uses double curly braces {{ }} to display the data. For example:</p><pre>&lt;h1&gt;{{ pageTitle }}&lt;/h1&gt;</pre><p>In this example, the pageTitle property of the component class is displayed in an h1 tag.</p><p><strong>Property Binding</strong></p><p>Property binding allows you to bind a property of an HTML element to a property of the component class. Property binding uses square brackets [] to bind the property. For example:</p><pre>&lt;img [src]=&quot;imageUrl&quot;&gt;</pre><p>In this example, the src property of an img tag is bound to the imageUrl property of the component class.</p><p><strong>Event Binding</strong></p><p>Event binding allows you to bind an event of an HTML element to a method of the component class. Event binding uses parentheses () to bind the event. For example:</p><pre>&lt;button (click)=&quot;save()&quot;&gt;Save&lt;/button&gt;</pre><p>In this example, the click event of a button element is bound to the save() method of the component class.</p><p><strong>Structural Directives</strong></p><p>Structural directives are used to conditionally render elements in the template. They are called structural directives because they change the structure of the HTML. Structural directives use the * symbol to define the directive. For example:</p><pre>&lt;div *ngIf=&quot;showContent&quot;&gt;Content&lt;/div&gt;</pre><p>In this example, the *ngIf directive will only render the div element if the showContent property in the component class is true.</p><h4>Conclusion</h4><p>Components and templates are key elements in the Angular framework. Components allow developers to break down complex web applications into smaller, reusable parts, while templates provide a way to separate the presentation layer from the business logic layer. The @Component() decorator is a TypeScript decorator that is used to mark a TypeScript class as an Angular component and provides metadata that Angular needs to create and manage the component. By understanding these concepts, developers can create powerful and maintainable web applications with Angular.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd73e0674340" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Angular]]></title>
            <link>https://medium.com/@aapawar/getting-started-with-angular-8e9984405554?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e9984405554</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 07:48:36 GMT</pubDate>
            <atom:updated>2023-04-13T07:48:36.314Z</atom:updated>
            <content:encoded><![CDATA[<h4>Key Features and Benefits</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8tt6PuaUvlTjocxreyGKg.png" /></figure><p>Angular is a widely popular open-source front-end web application framework that is used to build robust and dynamic web applications. Developed by Google, it has gained significant traction among developers due to its flexibility, scalability, and rich set of features.</p><p>In this article, we will discuss the basics of Angular, including its architecture, key features, and benefits. By the end of this article, you will have a good understanding of Angular and its capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lEvRiLt7l3StsC21Hh7y_Q.png" /></figure><h4>Angular Architecture</h4><p>Angular is built on a component-based architecture, which means that applications are composed of several components that work together to create a complete user interface. A component is a combination of HTML, CSS, and TypeScript code that defines the user interface of an application. It encapsulates the application logic and data, making it easier to manage and maintain.</p><p>The Angular framework consists of several building blocks that work together to create an application. These building blocks include:</p><ol><li><strong>Modules</strong>: Angular applications are divided into modules, which are a way of organizing the application into logical units. Each module is responsible for a specific feature or functionality of the application.</li><li><strong>Components:</strong> As mentioned earlier, components are the building blocks of an Angular application. They define the user interface of the application and encapsulate the application logic and data.</li><li><strong>Services: </strong>Services are used to provide functionality that can be shared across different components of an application. They are responsible for tasks such as data retrieval, data storage, and communicating with external APIs.</li><li><strong>Directives: </strong>Directives are used to add behavior to the HTML elements of an application. They can be used to manipulate the DOM, apply styling, or provide custom functionality.</li></ol><h4>Key Features of Angular</h4><p>Angular offers a wide range of features that make it an excellent choice for building web applications. Here are some of its key features:</p><ol><li><strong>Two-way data binding:</strong> Angular offers two-way data binding, which means that any changes made to the model are automatically reflected in the view, and vice versa. This makes it easier to manage and update the data of an application.</li><li><strong>Dependency injection:</strong> Angular uses dependency injection to manage the dependencies of an application. This means that components and services can be easily injected into other components and services, making it easier to share functionality across the application.</li><li><strong>Reactive programming:</strong> Angular uses reactive programming to manage asynchronous data streams. This makes it easier to handle complex data flows and update the UI in real-time.</li><li><strong>Routing:</strong> Angular offers a powerful routing system that allows developers to define and manage the navigation of an application. This makes it easier to create a smooth and seamless user experience.</li></ol><h4>Benefits of Angular</h4><p>Angular offers several benefits that make it a popular choice among developers. Here are some of its key benefits:</p><ol><li><strong>Rapid development:</strong> Angular makes it easier to develop and maintain complex applications. It&#39;s component-based architecture and powerful features make it easier to build robust and dynamic applications in less time.</li><li><strong>Scalability:</strong> Angular is highly scalable, which means that it can be used to build applications of any size. Its modular architecture and dependency injection system make it easier to manage large and complex applications.</li><li><strong>Cross-platform compatibility:</strong> Angular can be used to build applications for multiple platforms, including web, mobile, and desktop. This makes it a versatile framework that can be used to develop applications for a wide range of devices and platforms.</li><li><strong>Community support:</strong> Angular has a large and active community of developers who contribute to its development and provide support to other developers. This makes it easier to find solutions to problems and get help when needed.</li></ol><h4>Conclusion</h4><p>In conclusion, Angular is a powerful front-end web application framework that offers a wide range of features and benefits. Its component-based architecture, powerful features, and scalability make it an excellent choice for building complex and dynamic applications. Whether you are a beginner or an experienced developer, Angular is definitely worth considering for your next project.</p><p>As you have learned, Angular has a lot of key features, including two-way data binding, dependency injection, reactive programming, and routing. These features allow developers to create complex and dynamic applications in less time, making it easier to manage and maintain the codebase.</p><p>Angular also offers several benefits, including rapid development, scalability, cross-platform compatibility, and community support. These benefits make it a popular choice among developers, and ensure that it will continue to be a dominant force in the front-end web development landscape.</p><p>If you are interested in learning more about Angular, there are plenty of resources available online. The official Angular website provides documentation, tutorials, and a vibrant community forum. There are also many online courses and tutorials available on websites like Youtube, Udemy, and Coursera.</p><p>In conclusion, Angular is a powerful and flexible framework that can be used to build robust and dynamic web applications. Its component-based architecture, key features, and benefits make it a popular choice among developers. Whether you are building a small website or a large-scale application, Angular is definitely worth considering as a framework for your next project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e9984405554" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing GraphQL]]></title>
            <link>https://medium.com/@aapawar/securing-graphql-8e794951c06f?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e794951c06f</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 15:26:57 GMT</pubDate>
            <atom:updated>2023-04-03T15:26:57.892Z</atom:updated>
            <content:encoded><![CDATA[<h4>Authentication and Authorization</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leT1YPLnEdLhAb_bl-J8ZA.png" /></figure><p>Authentication and authorization are critical aspects of any web application. These mechanisms ensure that only authorized users can access sensitive information and perform actions that are allowed for their specific roles. GraphQL has built-in support for authentication and authorization, making it a popular choice for building secure web applications.</p><h3>Authentication in GraphQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*4pA_gLjOqpepRjw5bvQo7w.jpeg" /></figure><p>Authentication in GraphQL refers to the process of verifying the identity of a user. Once the identity is verified, the user is granted access to the application’s resources. GraphQL supports several authentication mechanisms, including token-based authentication, session-based authentication, and OAuth.</p><h4>Token-Based Authentication</h4><p>Token-based authentication is a popular mechanism used by GraphQL applications. In this approach, a token is issued to a user upon successful authentication. The token is then used to authenticate all subsequent requests made by the user. To implement token-based authentication in GraphQL, developers must define a custom middleware that checks the token’s validity for each request.</p><p>Here’s an example of a token-based authentication middleware in Node.js:</p><pre>const jwt = require(&#39;jsonwebtoken&#39;);<br><br>const authMiddleware = (req, res, next) =&gt; {<br>  const token = req.headers.authorization;<br>  if (!token) {<br>    res.status(401).json({ message: &#39;Unauthorized&#39; });<br>  } else {<br>    try {<br>      const decoded = jwt.verify(token, process.env.JWT_SECRET);<br>      req.user = decoded;<br>      next();<br>    } catch (err) {<br>      res.status(401).json({ message: &#39;Unauthorized&#39; });<br>    }<br>  }<br>};</pre><h4>Session-Based Authentication</h4><p>Session-based authentication is another common approach used by GraphQL applications. In this mechanism, a session is created for a user upon successful authentication. The session ID is then used to authenticate all subsequent requests made by the user. To implement session-based authentication in GraphQL, developers must configure the server to store and retrieve session data.</p><h4>OAuth</h4><p>OAuth is a widely-used authentication protocol that allows users to authenticate with third-party providers. In OAuth, a user grants access to their account to a third-party application, such as Facebook or Google. The third-party provider then issues an access token that can be used to authenticate subsequent requests made by the user.</p><h3>Authorization in GraphQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*RIs-XI3MpQ7SfJ9TtFUbIA.jpeg" /></figure><p>Authorization in GraphQL refers to the process of determining whether a user is authorized to access a particular resource or perform a specific action. GraphQL provides several authorization mechanisms, including role-based access control (RBAC), attribute-based access control (ABAC), and permission-based access control.</p><h4>Role-Based Access Control (RBAC)</h4><p>RBAC is a widely-used authorization mechanism in GraphQL. In this approach, users are assigned specific roles, such as admin, manager, or user. Each role is associated with a set of permissions that determine the actions the user can perform. To implement RBAC in GraphQL, developers must define a custom middleware that checks whether the user’s role allows them to perform the requested action.</p><p>Here’s an example of an RBAC middleware in Node.js:</p><pre>const rbacMiddleware = (req, res, next) =&gt; {<br>  const { user } = req;<br>  if (!user) {<br>    res.status(401).json({ message: &#39;Unauthorized&#39; });<br>  } else if (user.role === &#39;admin&#39;) {<br>    next();<br>  } else {<br>    res.status(403).json({ message: &#39;Forbidden&#39; });<br>  }<br>};</pre><h4>Attribute-Based Access Control (ABAC)</h4><p>ABAC is a more fine-grained authorization mechanism in GraphQL. In this approach, users are granted access to specific resources based on their attributes, such as age, location, or department. To implement ABAC in GraphQL, developers must define a custom middleware that checks whether the user’s attributes allow them to access the requested resource.</p><h4>Permission-Based Access Control</h4><p>Permission-based access control is another authorization mechanism used by GraphQL applications. In this approach, users are granted access to specific resources based on their individual permissions. Each user is assigned a set of permissions that determine the actions they can perform. To implement permission-based access control in GraphQL, developers must define a custom middleware that checks whether the user’s permissions allow them to perform the requested action.</p><p>Here’s an example of a permission-based access control middleware in Node.js:</p><pre>const permissionMiddleware = (permission) =&gt; (req, res, next) =&gt; {<br>  const { user } = req;<br>  if (!user) {<br>    res.status(401).json({ message: &#39;Unauthorized&#39; });<br>  } else if (user.permissions.includes(permission)) {<br>    next();<br>  } else {<br>    res.status(403).json({ message: &#39;Forbidden&#39; });<br>  }<br>};</pre><h3>Conclusion</h3><p>Authentication and authorization are critical aspects of any web application. GraphQL provides built-in support for these mechanisms, making it a popular choice for building secure web applications. Token-based authentication, session-based authentication, and OAuth are some of the authentication mechanisms used by GraphQL applications. RBAC, ABAC, and permission-based access control are some of the authorization mechanisms used by GraphQL applications.</p><p>By implementing these mechanisms, developers can ensure that only authorized users can access sensitive information and perform actions that are allowed for their specific roles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e794951c06f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutations in GraphQL]]></title>
            <link>https://medium.com/@aapawar/mutations-in-graphql-aa6e3f886a19?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa6e3f886a19</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[mutation]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 06:04:56 GMT</pubDate>
            <atom:updated>2023-04-03T06:04:56.358Z</atom:updated>
            <content:encoded><![CDATA[<h4>Manipulating Data with GraphQL Mutations</h4><p>GraphQL is a powerful query language for APIs that enables developers to create efficient and flexible APIs. It has gained immense popularity in recent years, thanks to its ability to efficiently retrieve data from various data sources. One of the key features of GraphQL is its ability to handle mutations, which are used to modify data on the server side. In this blog, we will explore mutations in GraphQL and provide examples of how they work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RgA1HGKO4dchEipyemz1sg.png" /></figure><h4><strong>What are Mutations in GraphQL?</strong></h4><p>Mutations in GraphQL are operations that enable developers to modify data on the server side. They are the counterpart to queries, which are used to retrieve data. Mutations are used when you want to modify or create data in the server-side database. For example, you may want to create a new user account, update an existing user account, or delete a user account.</p><p>Mutations in GraphQL work by defining a type that describes the input arguments and return values for the mutation. The type is defined in the schema, which is a document that describes the data that can be queried and manipulated using GraphQL. Once the schema is defined, developers can use it to execute mutations on the server.</p><h4>Example of Mutations in GraphQL</h4><p>Let’s look at an example of how mutations work in GraphQL. Suppose you have a simple application that allows users to create and update blog posts. You want to use GraphQL to create and update blog posts. Here is the schema that you would use to define the mutations:</p><pre>type Mutation {<br>  createPost(title: String!, content: String!): Post!<br>  updatePost(id: ID!, title: String, content: String): Post!<br>}<br><br>type Post {<br>  id: ID!<br>  title: String!<br>  content: String!<br>}</pre><p>The schema defines two mutations: createPost and updatePost. The createPost mutation takes two arguments, title and content, both of which are required. It returns a Post object, which contains the id, title, and content of the new blog post. The updatePost mutation takes three arguments, id, title, and content. The id argument is required, while title and content are optional. It returns a Post object with the updated id, title, and content.</p><p>To execute a mutation using GraphQL, you need to send a GraphQL mutation request to the server. Here’s an example mutation request that creates a new blog post:</p><pre>mutation {<br>  createPost(title: &quot;My First Blog Post&quot;, content: &quot;Hello World!&quot;) {<br>    id<br>    title<br>    content<br>  }<br>}</pre><p>This mutation request creates a new blog post with the title “My First Blog Post” and the content “Hello World!”. The response from the server will be a JSON object that contains the id, title, and content of the new blog post.</p><p>Similarly, here’s an example mutation request that updates an existing blog post:</p><pre>mutation {<br>  updatePost(id: &quot;1&quot;, title: &quot;My Updated Blog Post&quot;) {<br>    id<br>    title<br>    content<br>  }<br>}</pre><p>This mutation request updates the blog post with the ID of “1” and changes its title to “My Updated Blog Post”. The response from the server will be a JSON object that contains the id, title, and content of the updated blog post.</p><h4>Summary</h4><p>Mutations in GraphQL are like a form that allows you to create, update or delete information on a website or app. Just like how you fill out a form to enter your name, email, and other details, developers can define a mutation in GraphQL that takes in similar input arguments to create or update information on the server-side.</p><p>For example, if you’re signing up for a new account on a website, you’re essentially using a mutation to create a new user account. The website takes in your name, email, and password and creates a new account for you.</p><p>In the same way, developers can define a mutation in GraphQL that takes in input arguments such as name, email, and password and creates a new user account in the server-side database.</p><h4>Conclusion</h4><p>In this blog, we explored mutations in GraphQL and provided examples of how they work. Mutations are an essential feature of GraphQL that enables developers to modify data on the server side. They are defined in the schema and executed using GraphQL mutation requests. If you’re interested in learning more about GraphQL, there are plenty of resources available online.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa6e3f886a19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering GraphQL Resolvers]]></title>
            <link>https://medium.com/@aapawar/mastering-graphql-resolvers-d2afc5f9e8d6?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2afc5f9e8d6</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[graphql-resolver]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 05:01:42 GMT</pubDate>
            <atom:updated>2023-03-28T05:01:42.867Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Guide to Efficient API Development with Code Examples</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wR-zyCS_nBGhbK_h5_iRBg.png" /></figure><p>GraphQL is a powerful technology that allows developers to build efficient and flexible APIs. One of the key components of a GraphQL API is the resolver function. In this blog, we will explore resolvers in GraphQL in-depth and provide detailed explanations and code examples.</p><h3><strong>What are Resolvers?</strong></h3><p>In GraphQL, a resolver is a function that is responsible for returning the data for a specific field in a query. When a GraphQL query is executed, the resolver function is called to retrieve the data for each field in the query. Resolvers are a core component of a GraphQL server, and they are used to define the behavior of the server when it receives a query.</p><p>Resolvers are typically defined in a resolver map, which is a JavaScript object that maps each field in a GraphQL type to a resolver function. Here’s an example of a resolver map for a simple GraphQL type:</p><pre>const resolvers = {<br>  Query: {<br>    hello: () =&gt; &#39;Hello, world!&#39;<br>  }<br>};</pre><p>In the above example, we have defined a resolver for the hello field in the Query type. The resolver function simply returns the string &#39;Hello, world!&#39; when the hello field is queried.</p><h3>Resolver Function Signatures</h3><p>Resolver functions have a specific signature that they must follow. The signature of a resolver function depends on the type of field it is resolving. Here are the three different types of fields in a GraphQL schema and their corresponding resolver function signatures:</p><h4>Scalar fields:</h4><p>Scalar fields represent primitive values like strings, numbers, and booleans. The resolver function for a scalar field has the following signature:</p><pre>fieldName(parent, args, context, info) -&gt; result</pre><ul><li>parent: An object that contains the result returned by the resolver function for the parent field. This argument is typically not used for scalar fields.</li><li>args: An object that contains the arguments passed to the field in the query.</li><li>context: An object that is shared among all resolvers in a request. This object is used to store information that is relevant to the entire request, such as authentication and authorization data.</li><li>info: An object that contains information about the execution of the query, such as the AST of the query and the field&#39;s schema definition.</li><li>result: The result returned by the resolver function for the field.</li></ul><p>Here’s an example of a resolver function for a scalar field:</p><pre>const resolvers = {<br>  Query: {<br>    sayHello: (parent, args, context, info) =&gt; {<br>      return `Hello, ${args.name}!`;<br>    }<br>  }<br>};</pre><p>In the above example, we have defined a resolver function for the sayHello field in the Query type. The resolver function takes the args argument and returns a string that includes the name argument passed to the field in the query.</p><h4>Object fields:</h4><p>Object fields represent complex types like objects and arrays. The resolver function for an object field has the following signature:</p><pre>fieldName(parent, args, context, info) -&gt; result</pre><ul><li>parent: An object that contains the result returned by the resolver function for the parent field.</li><li>args: An object that contains the arguments passed to the field in the query.</li><li>context: An object that is shared among all resolvers in a request.</li><li>info: An object that contains information about the execution of the query.</li><li>result: The result returned by the resolver function for the field.</li></ul><p>Here’s an example of a resolver function for an object field:</p><pre>const resolvers = {<br>  Query: {<br>    getUser: (parent, args, context, info) =&gt; {<br>      return {<br>        id: &#39;123&#39;,<br>        name: &#39;John Doe&#39;,<br>        email : &#39;johndoe@example.com&#39;<br>      };<br>    }<br>  }<br>};</pre><p>In the above example, we have defined a resolver function for the getUser field in the Query type. The resolver function returns an object that represents a user, with properties like id,name, and email.</p><p>List fields:</p><p>List fields represent arrays of objects. The resolver function for a list field has the following signature:</p><pre>fieldName(parent, args, context, info) -&gt; [result]</pre><p>- parent: An object that contains the result returned by the resolver function for the parent field.<br>- args: An object that contains the arguments passed to the field in the query.<br>- context: An object that is shared among all resolvers in a request.<br>- info: An object that contains information about the execution of the query.<br>- result: An array of objects returned by the resolver function for the field.</p><p>Here’s an example of a resolver function for a list field:</p><pre>const resolvers = {<br>  Query: {<br>    getUsers: (parent, args, context, info) =&gt; {<br>      return [<br>        {<br>          id: &#39;123&#39;,<br>          name: &#39;John Doe&#39;,<br>          email: &#39;johndoe@example.com&#39;<br>          },<br>          {<br>          id: &#39;456&#39;,<br>          name: &#39;Jane Smith&#39;,<br>          email: &#39;janesmith@example.com&#39;<br>        }<br>      ];<br>    }<br>  }<br>};</pre><p>In the above example, we have defined a resolver function for the getUsers field in the Query type. The resolver function returns an array of objects that represent users.</p><h4>Conclusion</h4><p>In conclusion, resolvers are a core component of a GraphQL server, and they are used to define the behavior of the server when it receives a query. Resolvers are typically defined in a resolver map, which is a JavaScript object that maps each field in a GraphQL type to a resolver function. Resolver functions have a specific signature that they must follow, depending on the type of field they are resolving. By understanding how resolvers work in GraphQL, developers can build efficient and flexible APIs that meet their application’s needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2afc5f9e8d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Queries in GraphQL]]></title>
            <link>https://medium.com/@aapawar/queries-in-graphql-f3adbb9502bb?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3adbb9502bb</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nestjs]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 10:52:20 GMT</pubDate>
            <atom:updated>2023-03-27T10:52:20.814Z</atom:updated>
            <content:encoded><![CDATA[<h4>Writing efficient queries</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0S7k2bX4SxnMGEbgsd1Frw.png" /></figure><p>GraphQL is a query language that enables developers to fetch data from APIs with ease. In GraphQL, queries are used to retrieve data and mutations are used to modify data. The flexibility of GraphQL lies in the fact that it allows the client to define the shape of the data it wants to retrieve, reducing the amount of data returned and improving performance.</p><p>Queries in GraphQL are structured like JSON objects and consist of fields and arguments. A field is a piece of data that the client wants to retrieve, while an argument is used to filter and sort the returned data. In this blog, we will explore queries in GraphQL in-depth, along with examples.</p><p>Let&#39;s start with a simple query</p><pre>query {<br>  books {<br>    title<br>    author<br>  }<br>}</pre><p>In this query, we are retrieving the title and author fields of all books in the database. The response will look something like this:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;books&quot;: [<br>      {<br>        &quot;title&quot;: &quot;The Hitchhiker&#39;s Guide to the Galaxy&quot;,<br>        &quot;author&quot;: &quot;Douglas Adams&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;1984&quot;,<br>        &quot;author&quot;: &quot;George Orwell&quot;<br>      },<br>      ...<br>    ]<br>  }<br>}</pre><p>Notice that the response has the same structure as the query, and only returns the fields that were requested.</p><p>Arguments can be used to filter and sort the data returned by a query. Here’s an example:</p><pre>query {<br>  books(<br>    orderBy: &quot;title&quot;,<br>    limit: 5<br>  ) {<br>    title<br>    author<br>  }<br>}</pre><p>In this query, we are retrieving the title and author fields of the first 5 books in the database, sorted by title. The response will look something like this:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;books&quot;: [<br>      {<br>        &quot;title&quot;: &quot;1984&quot;,<br>        &quot;author&quot;: &quot;George Orwell&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Brave New World&quot;,<br>        &quot;author&quot;: &quot;Aldous Huxley&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Catch-22&quot;,<br>        &quot;author&quot;: &quot;Joseph Heller&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Dune&quot;,<br>        &quot;author&quot;: &quot;Frank Herbert&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Fahrenheit 451&quot;,<br>        &quot;author&quot;: &quot;Ray Bradbury&quot;<br>      }<br>    ]<br>  }<br>}</pre><p>We can also use arguments to filter data based on specific criteria. Here’s an example:</p><pre>query {<br>  books(<br>    filter: {<br>      author: &quot;J.K. Rowling&quot;<br>    }<br>  ) {<br>    title<br>    author<br>  }<br>}</pre><p>In this query, we are retrieving the title and author fields of all books in the database that were authored by &quot;J.K. Rowling&quot;. The response will look something like this:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;books&quot;: [<br>      {<br>        &quot;title&quot;: &quot;Harry Potter and the Philosopher&#39;s Stone&quot;,<br>        &quot;author&quot;: &quot;J.K. Rowling&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Harry Potter and the Chamber of Secrets&quot;,<br>        &quot;author&quot;: &quot;J.K. Rowling&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;Harry Potter and the Prisoner of Azkaban&quot;,<br>        &quot;author&quot;: &quot;J.K. Rowling&quot;<br>      },<br>      ...<br>    ]<br>  }<br>}</pre><p>In addition to fields and arguments, GraphQL queries can also include aliases, fragments, and variables. Aliases are used to rename fields in the response, while fragments are used to group fields together for reuse. Variables are used to pass values to arguments dynamically. Here’s an example:</p><pre>query GetBook($bookId: ID!) {<br>  book(id: $bookId) {<br>    ...BookFields<br>    }<br>  }<br>  <br>  fragment BookFields on Book {<br>  title<br>  author<br>  publisher<br>  publicationDate<br>}</pre><p>In this query, we are retrieving the `title`, `author`, `publisher`, and `publicationDate` fields of a `book` with a specific `ID`. We are using a fragment to group the fields together and make the query more readable. We are also using a variable to pass the `ID` of the book dynamically.</p><p>To execute this query, we need to pass a value for the `$bookId` variable. Here’s an example of how to do that in JavaScript:</p><pre>const GET_BOOK_QUERY = `<br>query GetBook($bookId: ID!) {<br>    book(id: $bookId) {<br>    ...BookFields<br>    }<br>  }<br>  <br>  fragment BookFields on Book {<br>    title<br>    author<br>    publisher<br>    publicationDate<br>  }<br>  `;<br>  <br>  const variables = {<br>    bookId: &#39;123&#39;<br>  };<br>  <br>  fetch(&#39;/graphql&#39;, {<br>        method: &#39;POST&#39;,<br>        headers: {<br>          &#39;Content-Type&#39;: &#39;application/json&#39;<br>        },<br>        body: JSON.stringify({<br>          query: GET_BOOK_QUERY,<br>          variables: variables<br>      })<br>  })<br>.then(response =&gt; response.json())<br>.then(data =&gt; console.log(data))<br>.catch(error =&gt; console.error(error));</pre><p>In this example, we are using the `fetch` API to send a `POST` request to our GraphQL API with the `GET_BOOK_QUERY` and `variables`. The response will be logged to the console.</p><p>In conclusion, GraphQL queries are a powerful way to retrieve data from APIs. They allow the client to define the shape of the data it wants to retrieve, reducing the amount of data returned and improving performance. Queries can include fields, arguments, aliases, fragments, and variables, making them flexible and easy to use. By understanding queries in GraphQL, developers can build more efficient and effective APIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3adbb9502bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficiently Query and Manipulate Data with GraphQL]]></title>
            <link>https://medium.com/@aapawar/efficiently-query-and-manipulate-data-with-graphql-344c46df28ab?source=rss-dfcde80026c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/344c46df28ab</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[query]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Asmita Pawar]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 06:49:06 GMT</pubDate>
            <atom:updated>2023-03-27T07:40:40.049Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Comprehensive Guide</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T4x-7hDVPZs2wG59gB7yVg.png" /></figure><p>GraphQL is a query language and a runtime that allows clients to request only the data they need from an API, which results in a more efficient transfer of data. It was developed by Facebook in 2012 and was released as an open-source project in 2015. Since then, it has become a popular alternative to REST APIs because of its flexibility and efficiency.</p><p><strong>Why GraphQL?</strong></p><p>GraphQL’s primary benefit is that it allows clients to specify exactly what data they need, rather than relying on the server to provide it. This means that the client can request data from multiple endpoints in a single request, which is not possible with REST APIs. This results in fewer requests and less data transfer, making the application faster and more responsive.</p><p>Another benefit of GraphQL is that it provides a clear and concise way to define the schema for your API. The schema defines the types of data that can be queried and manipulated, as well as the available queries and mutations. This makes it easier for developers to understand and work with the API, as well as making it easier to maintain and evolve over time.</p><p><strong>Using GraphQL</strong></p><p>To use GraphQL, you need to create a GraphQL server and a GraphQL client. There are several ways to create a GraphQL server, including using the graphql-yoga library, Apollo Server, or building a server with Express.js.</p><p>Once you have set up your server, you can define your GraphQL schema. The schema defines the types of data that can be queried and manipulated, as well as the available queries and mutations.</p><p>Queries are used to fetch data, while mutations are used to modify data. Here’s an example schema that defines a simple “Hello World” query:</p><pre>type Query {<br>  hello: String<br>}</pre><p>This schema defines a Query type with a hello field that returns a String.</p><p>To use this query, you can send a POST request to the GraphQL endpoint with a GraphQL query:</p><pre>type Mutation {<br>  addUser(name: String!, email: String!): User<br>}</pre><p>This schema defines a Mutation type with an addUser field that takes two arguments: name and email, both of which are required and must be strings. The mutation returns a User type.</p><p>To use this mutation, you can send a POST request to the GraphQL endpoint with a GraphQL mutation:</p><pre>mutation {<br>  addUser(name: &quot;John Doe&quot;, email: &quot;john@example.com&quot;) {<br>    name<br>    email<br>  }<br>}</pre><p>This mutation will add a new user with the name “John Doe” and email “<a href="/service/mailto:john@example.com">john@example.com</a>” to the database and return their name and email.</p><p><strong>GraphQL Clients</strong></p><p>To interact with a GraphQL server, you need to create a GraphQL client. There are several GraphQL clients available, such as Apollo Client and Relay. These clients allow you to query and mutate data from your GraphQL server and manage data caching.</p><p>Apollo Client is a popular client that works with React, Angular, and Vue.js. It allows you to write queries in a declarative way and provides tools for caching, pagination, and real-time updates. You can learn more about Apollo Client at <a href="https://www.apollographql.com/docs/react/">https://www.apollographql.com/docs/react/</a>.</p><p>Relay is another GraphQL client developed by Facebook. It is designed to work with React and provides tools for efficient data fetching, caching, and pagination. You can learn more about Relay at <a href="https://relay.dev/">https://relay.dev/</a>.</p><p><strong>Conclusion</strong></p><p>GraphQL is a powerful and efficient way to fetch and manipulate data over APIs. Its ability to provide precise data transfer and simplify API management makes it an attractive option for developers. With the resources available, getting started with GraphQL is relatively easy and can be done with various technologies.</p><p><em>In the upcoming blogs, we will learn about queries, resolvers and mutations in GraphQL.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=344c46df28ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>