You’ve probably heard about GraphQL technology for APIs as an alternative to REST APIs. However, let’s shortly recall what GraphQL is, its main purpose, and how we can use it in real life.

GraphQL was released in 2015 by Facebook and is positioned as an alternative to well-known RESTful architectural style. Instead of hundreds web API methods (which can obviously have different versions), you have only one Web API endpoint that allows you to get all information regarding the fields (a type of field, required or not, etc.). Essentially, GraphQL accepts the query — which is sort of JSON-formatted data — and tries to parse it to the previously defined schema.

You may post two types of queries:

Query — for getting multiple data and only those fields that are defined in a query

Mutation — uses for creating, updating, or deleting data

Let’s focus on getting data approach based on lightweight ORM NReco.Data ( which has a wide range DB-adapters and allowing connection to any popular DB — MSSQL, PostgreSQL, MySQL, Elasticsearch, ect.)and see how we can get data directly from database.

Component GraphQL.Net API to SQL-db allows us to define all schemas (even relations) in a JSON-formatted file. Let’s configure the schema and run a couple of queries for .NET Core Web Application step-by-step: