Skip to main content


Showing posts with the label Hot Chocolate

Hot Chocolate GraphQL Custom Authentication Series Using Pure Code First Technique - Part2 - Generating JWT(JSON Web Token) Access Token

Part1  discussed user registration. In this article, we are going to implement logic to generate the JWT access token in the Hot Chocolate GraphQL. Overview On JWT(JSON Web Token): JSON Web Token is a digitally signed and secured token for user validation. The jwt is constructed with 3 informative parts: Header Payload Signature Install JWT NuGet: Package Manager Command: Install-Package System.IdentityModel.Tokens.Jwt -Version 6.9.0 .Net CLI Command: dotnet add package System.IdentityModel.Tokens.Jwt --version 6.9.0 Add Token Settings: While generating the JWT access token, few token-specific settings need to be specified. appsettings.Development.json: "TokenSettings":{ "Issuer":"localhost:5001", "Audience":"", "Key":"SomeRandomlyGeneratedStringSomeRandomlyGeneratedString" } The 'Issuer' is like the identification of the server that generated the token. In access token 'iss'

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

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

Implementing DataLoader For Query Execution Using Hot Chocolate GraphQL In .Net

In this article, we are going to understand and implement the DataLoader concept in Hot Chocolate GraphQL. Here we will use an existing Hot Chocolate sample application that was created in the introduction articles on Hot chocolate GraphQL. I recommend reading those articles: Part-1 Introduction On Hot Chocolate GraphQL Part-2 Introduction On Hot Chocolate GraphQL Issues Need To Fix: Before implementing the DataLoader into our sample we must aware of the issues we are facing. In GrphQL we have an option like Fragments Query. Fragments query is used to display the comparison results very effective way. Fragments Query: query{ Gadget1:GetByBrand(brand:"samsung"){ Id ProductName Brand } Gadget2:GetByBrand(brand:"red mi"){ Id ProductName Brand } } Here we request a GraphQL endpoint to serve the different gadgets for comparison this type of query called Fragments Query. Now this kind of Fragments Query produces issues like: We will face