{"id":7593,"date":"2025-01-10T13:43:01","date_gmt":"2025-01-10T13:43:01","guid":{"rendered":"https:\/\/www.aegissofttech.com\/insights\/?p=7593"},"modified":"2025-05-27T13:33:54","modified_gmt":"2025-05-27T13:33:54","slug":"dot-net-8-api-with-graphql","status":"publish","type":"post","link":"https:\/\/www.aegissofttech.com\/insights\/dot-net-8-api-with-graphql\/","title":{"rendered":"How to Enhance .NET 8 API with GraphQL?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>What is GraphQL?<\/strong><\/h2>\n\n\n\n<p>Efficient data retrieval is critical in today&#8217;s data-driven world. An appealing substitute for conventional REST APIs is GraphQL, an open-source query language created by Facebook and published in 2015. It allows users to request exactly the data they need while maximizing efficiency and reducing data transfer. By integrating .NET 8 API with GraphQL, you gain flexibility, performance, and a better developer experience.<\/p>\n\n\n\n<p>GraphQL allows clients to retrieve multiple resources in a single request, in contrast to REST, which frequently leads to over-fetching (retrieving more data than needed) or under-fetching (requiring multiple requests to gather necessary information). Because it removes inefficiencies and simplifies data access, GraphQL has been used by companies like Facebook and GitHub to improve the performance of their APIs. It easily integrates with a number of .NET platforms, such as Azure Functions, and <a href=\"https:\/\/www.aegissofttech.com\/asp-net-core-development.html\" target=\"_blank\" rel=\"noreferrer noopener\">ASP.NET Core web applications<\/a>.<\/p>\n\n\n\n<p>The single endpoint design of GraphQL streamlines API design, lowering complexity and enhancing maintainability. This method provides a versatile, effective, and potent solution for creating contemporary applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Principal Benefits of GraphQL<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Accurate Data Requests: <\/strong>Customers provide the precise data they require, reducing needless data transfer and optimizing efficiency. This focused strategy is essential for increasing response times and optimizing bandwidth usage.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Complex Query Handling: <\/strong>GraphQL is very good at managing intricate data connections. It makes data retrieval easier for applications with complex data structures by enabling clients to request nested and related data in a single query.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Optimized Data Fetching: <\/strong>GraphQL guarantees that clients receive only the necessary data by removing over-fetching and under-fetching, reducing redundant data transfer and improving overall efficiency.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Leveraging Hot Chocolate for .NET 8 API with GraphQL Development<\/strong><\/h2>\n\n\n\n<p>Hot Chocolate is a robust, open-source GraphQL server specifically designed for the Microsoft .NET ecosystem. It simplifies the process of building GraphQL APIs within <a href=\"https:\/\/www.aegissofttech.com\/asp-dot-net-development-company.html\" target=\"_blank\" rel=\"noreferrer noopener\">.NET applications development services<\/a>, providing a range of features and benefits. It provides three main methods for GraphQL schema definition:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Schema-First: <\/strong>Use the Schema Definition Language (SDL) to define the GraphQL schema, and then use resolvers to retrieve the data. This method provides concern separation and type checking.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Code-First: <\/strong>Use C# classes to define data models, and Hot Chocolate will automatically create the GraphQL schema that goes with them. This method uses pre-existing code structures to expedite development.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Annotation-Based: <\/strong>This approach defines the GraphQL schema directly in the code by using attributes to annotate C# classes and methods. A succinct and comprehensive development experience is provided by this method.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Principal Benefits of Hot Chocolate<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ease of Use: <\/strong>Hot Chocolate offers a fluent API and user-friendly tools for schema definition, query execution, and data fetching, making it easier to develop GraphQL APIs with.NET.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Performance Optimization: <\/strong>Caching techniques, effective data loading techniques, and query optimization are all part of Hot Chocolate&#8217;s performance-enhancing architecture.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Platform Flexibility: <\/strong>Hot Chocolate facilitates the development of GraphQL APIs for a variety of application types by supporting a broad range of .NET platforms and deployment scenarios.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Customization and Extensibility:<\/strong> Hot Chocolate provides a wide range of middleware components and features that can be expanded and modified to satisfy particular project needs.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Strong Community Support: <\/strong>Hot Chocolate has a thriving community and extensive documentation, which gives developers access to a wealth of resources and assistance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Demo<\/strong><\/h2>\n\n\n\n<p>Now, let\u2019s create a demo using .NET 8 API with GraphQL integration with Hot Chocolate wrapper.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Pre-Requisite<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>.NET 8 SDK<\/li>\n\n\n\n<li>Visual Studio code<\/li>\n\n\n\n<li>Basic <a href=\"https:\/\/www.aegissofttech.com\/insights\/grpc-vs-rest\/\" target=\"_blank\" rel=\"noreferrer noopener\">understanding of REST<\/a> API concepts<\/li>\n<\/ol>\n\n\n\n<p>=&gt; Download .NET SDK for Windows or Mac based on your operating system from <a href=\"https:\/\/dotnet.microsoft.com\/en-us\/download\/visual-studio-sdks\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/dotnet.microsoft.com\/en-us\/download\/visual-studio-sdks<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"394\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studios-sdks-1024x394.jpg\" alt=\"Visual Studios SDKs\" class=\"wp-image-7594\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studios-sdks-1024x394.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studios-sdks-300x115.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studios-sdks-768x296.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studios-sdks.jpg 1429w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>=&gt; Download Visual Studio code from Microsoft\u2019s official website <a href=\"https:\/\/code.visualstudio.com\/Download\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/code.visualstudio.com\/Download<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"480\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/download-visual-studio-code-1-1024x480.jpg\" alt=\"Download Visual Studio Code\" class=\"wp-image-7595\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/download-visual-studio-code-1-1024x480.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/download-visual-studio-code-1-300x141.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/download-visual-studio-code-1-768x360.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/download-visual-studio-code-1.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once you install .NET SDK, type the below command and you should see the result like below. If the result is something different, then there might be some issue with .net installation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"317\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/dot-net-installation-info-1024x317.png\" alt=\"Dot Net Installation Info\" class=\"wp-image-7596\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/dot-net-installation-info-1024x317.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/dot-net-installation-info-300x93.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/dot-net-installation-info-768x238.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/dot-net-installation-info.png 1498w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once you install VS Code, just type \u201ccode .\u201d In the terminal, and it should open Visual Studio Code GUI.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"551\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studio-code-gui-1024x551.jpg\" alt=\"Visual Studio Code GUI\" class=\"wp-image-7597\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studio-code-gui-1024x551.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studio-code-gui-300x162.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studio-code-gui-768x414.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/visual-studio-code-gui.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1<\/strong>:<\/h3>\n\n\n\n<p>=&gt; Create a new web api project using .NET CLI.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"108\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/new-web-api-project.jpg\" alt=\"New Web API Project\" class=\"wp-image-7598\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/new-web-api-project.jpg 1018w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/new-web-api-project-300x32.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/new-web-api-project-768x81.jpg 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2:<\/strong><\/h3>\n\n\n\n<p>=&gt; Open the newly created project in Visual Studio Code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"252\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/newly-created-project-in-visual-studio.jpg\" alt=\"Create Project in Visual Studio Code\" class=\"wp-image-7599\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/newly-created-project-in-visual-studio.jpg 708w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/newly-created-project-in-visual-studio-300x107.jpg 300w\" sizes=\"(max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3:<\/strong><\/h3>\n\n\n\n<p>=&gt; Install the below 3 Hot Chocolate packages to integrate .NET 8 API with GraphQL.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"79\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-1-1024x79.jpg\" alt=\"Hot Chocolate Package 1\" class=\"wp-image-7600\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-1-1024x79.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-1-300x23.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-1-768x59.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-1.jpg 1040w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"77\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-2-1024x77.jpg\" alt=\"Hot Chocolate Package 2\" class=\"wp-image-7601\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-2-1024x77.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-2-300x23.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-2-768x58.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-2.jpg 1324w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"62\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-3-1024x62.jpg\" alt=\"Hot Chocolate Package 3\" class=\"wp-image-7602\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-3-1024x62.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-3-300x18.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-3-768x47.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/hot-chocolate-package-3.jpg 1156w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>=&gt; Your .csproj file should look like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"90\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/csproj-file-1024x90.jpg\" alt=\"csproj file\" class=\"wp-image-7603\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/csproj-file-1024x90.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/csproj-file-300x26.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/csproj-file-768x68.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/csproj-file.jpg 1428w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4:<\/strong><\/h3>\n\n\n\n<p>=&gt; Create a file named ModuleInfo.cs in the Properties folder and write the below code. This file will tell the .NET to include Module of types from Hot chocolate package.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"236\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/module-info-properties-1024x236.jpg\" alt=\"Module Info in Properties Folder\" class=\"wp-image-7604\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/module-info-properties-1024x236.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/module-info-properties-300x69.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/module-info-properties-768x177.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/module-info-properties.jpg 1300w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5:<\/strong><\/h3>\n\n\n\n<p>=&gt; Create a new folder named Types and add the following files with the corresponding code.<\/p>\n\n\n\n<p>=&gt; We are creating a very basic example of an employee who belongs to a department.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"420\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-types.jpg\" alt=\"Create Folder Types\" class=\"wp-image-7605\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-types.jpg 638w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-types-300x197.jpg 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<p>=&gt; Here we create Department having a name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"193\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-department-1024x193.jpg\" alt=\"Create Department Type\" class=\"wp-image-7606\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-department-1024x193.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-department-300x56.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-department-768x144.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-department.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>=&gt; Here we create an employee who belongs to a department.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"191\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-employee-1024x191.jpg\" alt=\"Create Employee belongs to Department\" class=\"wp-image-7607\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-employee-1024x191.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-employee-300x56.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-employee-768x143.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/create-employee.jpg 1431w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>=&gt; Finally we create a query with some hardcoded employee and department. The main item to focus here is the QueryType attribute. This is responsible for telling the hot chocolate that this is a schema relationship.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"316\" data-id=\"7608\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/querytype-attribute-1024x316.jpg\" alt=\"QueryType Attribute with Employee and Department\" class=\"wp-image-7608\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/querytype-attribute-1024x316.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/querytype-attribute-300x93.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/querytype-attribute-768x237.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/querytype-attribute.jpg 1431w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 6:<\/strong><\/h3>\n\n\n\n<p>=&gt; Update the program.cs file code with the below code. Here we are adding GraphQL to the pipeline and also adding types so that it can create a schema relationship of Employee and Department.<\/p>\n\n\n\n<p>=&gt; MapGraphQL method creates the GraphQL endpoint, which is the only single endpoint that will be exposed to the outer world for consumption.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/program-cs-file-code-1024x572.png\" alt=\"Program.cs File Code\" class=\"wp-image-7609\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/program-cs-file-code-1024x572.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/program-cs-file-code-300x168.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/program-cs-file-code-768x429.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/program-cs-file-code.png 1274w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>=&gt; Update the launchSettings.json file configuration to use graphql as the entry point. I have changed the launchUrl to use GraphQL server.<\/p>\n\n\n\n<p>=&gt; The \/graphql is added by the MapGraphQL method of Program.cs file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"366\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/launchsettings-json-file-configuration-1024x366.jpg\" alt=\"launchsettings json File Configuration\" class=\"wp-image-7610\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/launchsettings-json-file-configuration-1024x366.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/launchsettings-json-file-configuration-300x107.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/launchsettings-json-file-configuration-768x275.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/launchsettings-json-file-configuration.jpg 1428w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 7:<\/strong><\/h3>\n\n\n\n<p>=&gt; Run the application using the following command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"296\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/run-application-using-command-1024x296.jpg\" alt=\"Run Application using Command\" class=\"wp-image-7611\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/run-application-using-command-1024x296.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/run-application-using-command-300x87.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/run-application-using-command-768x222.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/run-application-using-command.jpg 1431w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 8:<\/strong><\/h3>\n\n\n\n<p>=&gt; Go to the http localhost URL and you should see the GraphQL Nitro interface.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"599\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/graphql-nitro-interface-1024x599.jpg\" alt=\"GraphQL Nitro Interface\" class=\"wp-image-7612\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/graphql-nitro-interface-1024x599.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/graphql-nitro-interface-300x176.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/graphql-nitro-interface-768x450.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/graphql-nitro-interface.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 9:<\/strong><\/h3>\n\n\n\n<p>=&gt; Click on Create Document and you shall see the playground.<\/p>\n\n\n\n<p>=&gt; In the playground, you can see the URL of the API on the top right corner. And in the Bottom right corner, you can see that the schema is available which means it is able to create a schema of the available types in the code, in this case, employee and department.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"567\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-create-document-1024x567.jpg\" alt=\"Click on Create Document\" class=\"wp-image-7613\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-create-document-1024x567.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-create-document-300x166.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-create-document-768x425.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-create-document.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 10:<\/strong><\/h3>\n\n\n\n<p>=&gt; Click on Schema button, and you should see the exact Schema that we created with Employee and Department.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"358\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-schema-button-1024x358.jpg\" alt=\"Click on Schema Button\" class=\"wp-image-7614\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-schema-button-1024x358.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-schema-button-300x105.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-schema-button-768x269.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/click-on-schema-button.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"448\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/created-with-employee-and-department-1024x448.jpg\" alt=\"Created with Employee and Department\" class=\"wp-image-7616\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/created-with-employee-and-department-1024x448.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/created-with-employee-and-department-300x131.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/created-with-employee-and-department-768x336.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/created-with-employee-and-department.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 11:<\/strong><\/h3>\n\n\n\n<p>=&gt; Let\u2019s try to execute a GraphQL query where we will pull all employees with their department name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"462\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/execute-a-graphql-query-1024x462.jpg\" alt=\"Execute GraphQL Query\" class=\"wp-image-7615\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/execute-a-graphql-query-1024x462.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/execute-a-graphql-query-300x135.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/execute-a-graphql-query-768x346.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/execute-a-graphql-query.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 12:<\/strong><\/h3>\n\n\n\n<p>=&gt; For instance, I only want to pull employee names, so I can rewrite the query like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"454\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/pull-employee-names-query-1024x454.jpg\" alt=\"Pull Employee Names Query\" class=\"wp-image-7617\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/pull-employee-names-query-1024x454.jpg 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/pull-employee-names-query-300x133.jpg 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/pull-employee-names-query-768x340.jpg 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2025\/01\/pull-employee-names-query.jpg 1430w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>So, in last two steps, you saw that we can modify the request payload as per the need. In first example, we needed both employee and department with a relationship. And in second example we only needed employee names. The magic of GraphQL is that you don\u2019t have to make any code change to make this happen unlike REST API.<\/p>\n\n\n\n<p>You can generate the required response on demand without the need to make any code change. This makes .NET 8 API with GraphQL a better choice for apps which have more data processing and frequency is high.<\/p>\n\n\n\n<p>Hope you can understand the concept and it is highly customizable. You can research more on .NET 8 API with GraphQL features like mutations, subscription, etc.<\/p>\n","protected":false},"excerpt":{"rendered":" ","protected":false},"author":1,"featured_media":7639,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[190],"tags":[1044,1046,1045,1048,1047],"class_list":["post-7593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","tag-net-8-api","tag-net-8-graphql","tag-api-development","tag-graphql-for-net","tag-graphql-integration"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/7593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/comments?post=7593"}],"version-history":[{"count":11,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/7593\/revisions"}],"predecessor-version":[{"id":10705,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/7593\/revisions\/10705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/media\/7639"}],"wp:attachment":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/media?parent=7593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/categories?post=7593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/tags?post=7593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}