Skip to main content


Showing posts with the label Hot Chocolate V12

Hot Chocolate GraphQL Pagination Using UseOffsetPaging Middleware[.NET6]

In this article, we are going to understand the GraphQL pagination using the 'UseOffsetPaging' middleware. UseOffsetPaging Middleware: Hot chocolate provides default pagination middleware that is 'UseOffsetPaging'. Simply applying 'UseOffsetPaging' on the resolver method will enable the pagination. This middleware implicitly reads the variables like 'skip' and 'take' from the request query and then generates the raw SQL query from the IQueriable. Create A .NET6 Web API Project: Let's create a .Net6 Web API sample application to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any .NET6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. .NET CLI Command: dotnet new webapi -o Your_Project_Name Sample Table Data: Let's have a sample Todo table as shown. Setup EntityFramework Core Database Context: Let's

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

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