Skip to main content

Posts

Showing posts with the label GraphQL

An Overview On Hot Chocolate GraphQL Implementation In Pure Code First Approach

In this article, we are going to understand Hot Chocolate GraphQL implementation in pure code first approach. 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 instead backed by your existing code and data. GraphQL 2 main operations: Query(fetching data) Mutation(saving or updating data) An Overview On GraphQL SDL(Schema Definition Language): In GraphQL queries or mutations made up of Schema Definition Language. This SDL syntax looks similar to a javascript object. But as a c# developer no need to learn this SDL, Hot Chocolate library makes our learning path very easy in this case. So this section is to get the basic idea of the SDL. GraphQL schema objects are created by usin

Hot Chocolate GraphQL Extending Object Types To Split Large Query And Mutation Classes

How GraphQL Extending Object Types Helps?: In GraphQL two major operations are 'Queries' and 'Mutations'.  So when we think from the code point of view all query-related logics maintain in one file and all mutation-related logics are maintained in another file. That's because GraphQL schema can't accept multiple 'Queries' and 'Mutations'. But it is a very tedious job to maintain whole business logic in just 2 files(1Query and 1 Mutation file). So to make it simple GraphQL has one technique called 'extend'. The 'extend' GraphQL schema gives us the flexibility to extend the main 'Query' or 'Mutation' which means we can have sub Queries or Mutation those derived from the parent. On execution time everything merged as a single Query or Mutation schema. Hot Chocolate GraphQL Extending Approaches: Extending Object Types can be done in 2 different approaches: Code First Pure Code First Code First: In the code first ap

Angular Application To Consume GraphQL Endpoint Using Apollo Angular Library

In this article, we will learn about consuming GraphQL API from angular applications using the Apollo Angular library. Overview On GraphQL API: As a front-end developer, no need to understand about in-depth nature of the GraphQL API. But it will be good to know about few key features about it for development. GraphQL API mostly has a single endpoint. So data fetching or updating will be carried out by that single endpoint. For posting data or querying data, we have to follow its own syntax. GraphQL carries two important operations: Query - fetching data Mutation - updating or saving data. Create A Sample Angular Application: Let's create a sample angular application where we are going to implement techniques to consume the GraphQL endpoint. Command To Install Angular CLI:(If not installed on your system previously) npm install -g @angular/cli Angular CLI Command To Create Angular App: ng new your_project_name Command To Run App: ng serve Install Apollo Angular Library: Apo

Part-2 Hot Chocolate GraphQL Validate JWT Access Token And Different Authorization Techniques

Part-1  completely discussed the steps to generate the access token in the GraphQL endpoint. Now in this article, our main goals are to validate the JWT access token and also we try to understand authorization techniques in GraphQL. Install JwtBearer Authentication NuGet: Let's install JwtBearer Authentication NuGet to configure JwtBearer services. .Net CLI Command: dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer Package Manager Command: Install-Package Microsoft.AspNetCore.Authentication.JwtBearer Register JWT Validation Service: Now we need to register the JwtBearer service to validate our access token on the user sending the access token as an authorization header. Startup.cs: using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = Con

Part-1 Hot Chocolate GraphQL JWT(JSON Web Token) Authentication - Generating User Login Access Token

In this article, we are going to implement a JWT authentication sample for the Hot Chocolate GraphQL endpoint. It's purely optional to implement JWT authentication in the GarphQL approach. Because .Net supports endpoint configuration for both normal .Net endpoint and GraphQL endpoint. While implementing GraphQL in your application and if you want to develop an authentication endpoint in the .Net approach there is no issue. But if you want to develop all endpoint in GraphQL including authentication that is also fine. So in this article, our goal is to create JWT authentication as a GraphQL endpoint. Create A .Net5 Web API Application: To understand the concept let's start our journey by creating a sample .Net5 Web API application. Recommended IDE for development are like Visual Studio 2019(Version 16.8.* for .Net5) or  Visual Studio Code . Install Hot Chocolate Library: Package Manager Command: Install-Package HotChocolate.AspNetCore -Version 11.0.2 .Net CLI Command: dotn