Skip to main content

Posts

Showing posts from January, 2022

A Basic GraphQL CRUD Operation With .NET6 + Hot Chocolate(V 12) + SQL Database

In this article, we are going to implement GraphQL CRUD operation in .NET6, Hot Chocolate(V12), SQL Database. GraphQL: GraphQL is an open-source data query and manipulation and language for APIs. It is a query language for your API and a server-side runtime for executing queries by using a type system you define for your data. GraphQL can be integrated into any framework like .NET, Java, NestJS, etc and it isn't tied to any specific database or storage engine and is backed by your existing code and data. GraphQL 2 main operations are like: Query(fetching data) Mutation(data manipulation like save, update, delete) Hot Chocolate GraphQL: Hot Chocolate is an open-source GraphQL server that is compliant with the newest GraphQL latest specs. It is the wrapper library of the original .NET GraphQL library. Hot Chocolate takes the complexity away from building a fully-fledged GraphQL server. Create A .NET6 Web API Project: Let's create a .Net6 Web API sample application to accompli

A Demo For Understand Search Relevance In ElasticSearch Using Kibana

In this article, we will understand Relevance Search in ElasticSearch using Kibana. Click here for a basic CRUD operation demon on ElasticSearch using Kibana . Relevance Search: In Elasticsearch relevance search means the output of the search can be done in 2 different ways like 'Precision', 'Recall'. The 'Precision' result means the most accurate results from the ElasticSearch. This means it fetches exact matches of the search value. So in this search output will be more accurate, but the total output results count might be very very less. Here all green color docs are more accurate documents for the search. Here all red color docs are either less accurate documents or not matching documents for the search. Here we can observe search results contain only accurate documents which means it is a 'Precision' result. The 'Recall' results mean more in the count of the output results because it fetches partially matched data along with accurate dat

Hot Chocolate GraphQL Pagination Using Cursor Technique[.NET 6]

In this article, we are going to understand the Cursor Pagination technique in Hot Chocolate GraphQL. GraphQL Cursor Paging: In GraphQL we have cursor-based pagination. The cursors are opaque, either offset or ID-based pagination can be implemented. In the cursor-base pagination based on request Graphql query response return 'Edges', 'PageInfo'(object). Edges consist of an array of objects with properties like 'node', 'cursor'. So 'node' property holds single record data into it. 'cursor' is a base64 string that can be either made by the row number or record primary key id value. So each 'edge' contains 'node'(contains single record data) along with 'cursor', so using the 'cursor' value we can query our server to return the records either before or after the 'cursor' value. PageInfo consist of  'hasNextPage', 'hasPreviousPage', 'startCursor', 'endCursor'. Sample Query

A Basic CRUD Operation Demo On Elasticsearch Using Kibana

In this article, we will understand the way to implement Elasticsearch CRUD operation using the Kibana tool. Elasticsearch: Elasticsearch is a distributed, free, and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. It provides simple REST APIs, distributed nature, speed, and scalability. Elasticsearch stores data in JSON format. so each JSON format data record in elastic search is called a document. So documents are queried or searched by the Index, Index holds the reference to respective documents. Elasticsearch use cases: Application Search Website Search Enterprise search Loggin and log analytics Infrastructure metrics and container monitoring Application performance monitoring Kibana: Kibana is a free and open frontend application that sits on top of the Elastic Stack, providing search and data visualization capabilities for data indexed in Elasticsearch. Run Elasticsearch And Kibana Docker Containe

Part-4 Blazor Server Cookie Authentication

In this article, we implement the logic for the user logout from the Blazor server application. In this part of our article, we have to accomplish our targets like: SignOut Implementation. Generating Anti-Forgery Token. Create Sign-Out Razor Page: Since for logout we no need any UI page so we can implement our c# logic directly into the razor page so creating 'Logout.csthml' single file is enough. Areas/Identity/Pages/Accoun/Logout.cshtml: @page "/identiy/account/logout" @using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Authentication.Cookies @inject IHttpContextAccessor _accessor @functions { public async Task<IActionResult> OnPostAsync() { await _accessor.HttpContext .SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return Redirect("~/"); } } Here to sign out the user from the application w will use the 'Httpcontext.SignOutAsyn()' method by sending the authentica

Part-3 Blazor Server Cookie Authentication

In this article, we are going to implement a 'User Login Page' in our Blazor Server application. In this part of the article, we have to accomplish our targets like: Login User Form. Login Authentication Logic. Configuring Cookie Authentication Service. Installing Blazor Authorization Package 'Microsoft.AspNetCore.Components.Authorization'. Adding the 'CascadingAuthenticationState' component. Using the 'AuthorizeView' component. Login Password Validation: Let's add logic to validate the user entered password in the login form against the user hash password stored in the database. Logic/AccountLogic: private bool ValidatePasswordHash(string password, string dbPassword) { byte[] dbPasswordHashBytes = Convert.FromBase64String(dbPassword); byte[] salt = new byte[16]; Array.Copy(dbPasswordHashBytes, 0, salt, 0, 16); var userPasswordBytes = new Rfc2898DeriveBytes(password, salt, 1000); byte[] userPasswordHash = userPasswordBytes.GetBytes(20);