asp.net core

GraphQL with ASP.NET Core (Part- IX : Entity Relations - Many to Many)

Read the previous part - GraphQL with ASP.NET Core (Part- VIII : Entity Relations - One to Many) We have an opportunity to show off a many-to-many relation in our sample app and I don't want to miss that. In a real-world scenario, only a limited quantity of a particular item belongs to a particular order. Imagine, you have an order cart containing references to some selected items with their respective ordered quantities. The end result is you got a relationship something like: an order can have many items whereas…

Keep reading

GraphQL with ASP.NET Core (Part- VIII : Entity Relations - One to Many)

Read the previous part - GraphQL with ASP.NET Core (Part- VII : Mutation) Building a GraphQL end-point with a single entity ain't gonna cut it. In this post, we introduce two new entities for handling orders for a customer. The relationship between Customer and Order is one-to-many i.e. A customer can have one or many orders, whereas a particular order belongs to a single customer. You can configure entity relationship following entity framework conventions. Entity framework will auto-create a one-to-many relationship between entities if one of the entity contains…

Keep reading

GraphQL with ASP.NET Core (Part- VII : Mutation)

Read the previous part - GraphQL with ASP.NET Core (Part- VI : Persist Data - Postgres with EF Core) We've been dealing with data fetching so far. But how do you cause side effects on the server-side data? Side effects can be anything ranging from a data insertion, patching, deletion or update. GraphQL mutation is just the thing you are looking for here. Before we move forward, I would like to do a bit of housekeeping on the project. So, I've changed the name of the HelloWordQuery object graph type…

Keep reading

GraphQL with ASP.NET Core (Part- V : Fields, Arguments, Variables)

Read the previous part - GraphQL with ASP.NET Core (Part- IV : GraphiQL - An in-browser IDE) Fields We already have a good idea of GraphQL Fields. Remember we had two fields under the HelloWorldQuery i.e. hello and howdy. Both of them were scaler fields. As the official documentation states, "At its simplest, GraphQL is about asking for specific fields on objects" - graphql.org Let's extend our simple application to accommodate a complex type. Say, for example, we are heading towards a path of making an Inventory system.…

Keep reading

GraphQL with ASP.NET Core (Part- IV : GraphiQL - An in-browser IDE)

Read the previous part - GraphQL with ASP.NET Core Part- III : Dependency Injection GraphiQL (spelled graphical) is an in-browser IDE for exploring GraphQL. I think it's a must-have tool for any server running behind GraphQL. With GraphiQL in place, you can easily give yourself or your team an in-depth insight of your API. There are setups you have to do first. We need some packages installed. Create a package.json file and paste the following snippet, { "name": "GraphQLAPI", "version": "1.0.0", "main": "index.js", "author": "Fiyaz Hasan", "license"…

Keep reading

GraphQL with ASP.NET Core (Part- II : Middleware)

Read the previous part - GraphQL with ASP.NET Core Part- I : Hello World If you are familiar with ASP.NET Core middleware[1], you may have noticed that in our previous post we already had a middleware. In the initial blank app, that middleware was responsible for throwing a Hello World response. Later we replaced it with our custom code so that it can respond back a result of some static GraphQL query. Middleware is software that's assembled into an application pipeline to handle requests and responses. Each component:…

Keep reading

GraphQL with ASP.NET Core (Part- I : Hello World)

Tired of REST? Let's talk about GraphQL. GraphQL provides a declarative[1] way in which you can fetch data from the server. You can read about every bit of goodness that is baked into GraphQL in the official site. However, in this series of blog posts, I'm going to deal with ASP.NET Core and will show how you can integrate GraphQL with it and use it as a query language for your API. Meaning that you only declare the properties you need (In contrast to restful API where you…

Keep reading

Migrating from the old ASP.NET Core Angular Spa template to the newer one

Client Side Changes: If you are using the ASP.NET Core Angular SPA template that has been shipped with the .NET Core 2.0 release of the framework, you will have the following project structure. Assuming that you put your application scripts under the ClientApp/app folder. So, before migrating, take a back up of the folder. Delete the ClientApp folder altogether. We will generate the folder with the Angular CLI. On the project root directory, open up a command prompt window and generate an Angular app by running the…

Keep reading

About The Updated SPA Templates From ASP.NET Core

Install the new spa templates by running the following dotnet cli command, dotnet new --install Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-preview1-final More or less everyone working with ASP.NET Core, tried out the following SPA templates shipped with the framework, These templates are configured to use Angular/React/ReactRedux (based on your choice) on the client side and ASP.NET Core as back-end. Behind the scene a package Microsoft.AspNetCore.SpaServices is used as a middleware to provide different configurable options for your application such as HMR (Hot…

Keep reading

Story of File Uploading in ASP.NET Core (Part II - Angular/AJAX)

Uploading files from Angular end to an ASP.NET Core Web API can be done using the same IFormFile interface; introduced in the previous post. To keep things separated, a new API controller (UserController) has been created with the following POST action, [HttpPost] public async Task<IActionResult> PostUser([FromForm]UserVM vm) { if (!ModelState.IsValid) { return BadRequest(ModelState); } /* Use Automapper for mapping UserVM to User */ User user = new User { Name = vm.Name }; using (var memoryStream = new MemoryStream()) { await vm.Avatar.CopyToAsync(memoryStream); user.Avatar = memoryStream.ToArray(); } _context.Users.Add(…

Keep reading