When the mobile order screen of a dealer portal opens, the phone calls four separate addresses: orders, line items, customer card, balance. Every response also carries fields the screen never shows. When the team wants a new screen, it waits for the back-end team to build a new endpoint. This is where the question what is GraphQL comes up: it is a query language in which the client states in one query which fields it wants, and the server returns only those. It is not the right path for every API, though, and it has costs of its own.
In this guide we explain what GraphQL is, the concepts of schema, query and mutation, its effect on call count and data volume, the N+1 problem and batched loading, query depth and cost limits, field-level authorization, the caching difficulty, a six-question decision test and the payback calculation. REST has its own design rules in a separate guide; here we focus on GraphQL itself. All figures are illustrative; they are not real measurements or industry averages.
What Is GraphQL?
GraphQL is a query language for APIs and a runtime that executes those queries. The server exposes a single endpoint and describes the shape of its data with a schema; the client writes in the query which objects and fields it needs from that schema. The response follows the shape of the query exactly: what was asked for arrives, nothing more.
This approach has two consequences. Related data (an order, its line items, their products) can be fetched in one request, and each screen can choose its own set of fields. In return, the server must now be ready for query shapes it did not know in advance. We covered the general logic of connecting other systems to an existing API in our API integration guide.
We recommend reading: How to design a REST API: resource naming, pagination and error format guide
How Does GraphQL Work? Schema, Query, Mutation and Resolver
Five concepts are enough: the schema defines the contract, a query reads, a mutation writes, and a resolver defines where each field gets its data.
| Concept | What it does | Dealer portal example |
|---|---|---|
| Schema | Defines objects, fields and types; it is the contract | Order, Line Item and Product objects; the type of every field |
| Query | Reads data; the client selects fields | Latest 20 orders: number, status, line items |
| Mutation | Changes data | Create an order, cancel an order |
| Subscription | Pushes data to the client when an event occurs | Order status changed notification |
| Resolver | Fetches the value of a field from the database or another service | An order's customer field is read from the customer table |
Every field in the schema is typed and marked as nullable or non-nullable, so the expectation between client and server stays in writing. For write operations, the duplicate protection from the REST guide applies here too: a system whose mutation carries no operation key can create duplicate orders after a network interruption. When a query reaches the server, it follows this path.
How Does GraphQL Reduce Call Count and Data Volume?
There are two gains: related data arrives in one round trip, and the response carries only the requested fields. Let us run an illustrative calculation for a mobile order screen. Assume each round trip takes 160 ms.
| REST call | Dependency | Time |
|---|---|---|
| 1. Latest orders | Independent | 160 ms |
| 2. Order line items | Depends on 1 (needs the order ID) | 160 ms |
| 3. Customer card | Independent (the signed-in dealer) | 160 ms |
| 4. Balance summary | Independent | 160 ms |
| Sequential total | Each call waits for the previous one | 4 × 160 = 640 ms |
| Two waves | 1, 3 and 4 in parallel; then 2 | 2 × 160 = 320 ms |
If the client runs independent calls in parallel, the time drops to 320 ms; this middle path is often overlooked. A single GraphQL query has one round trip (160 ms) plus about 30 ms on the server to resolve the fields: 160 + 30 = 190 ms. Against two-wave REST the difference is 320 − 190 = 130 ms; against the sequential case it is 640 − 190 = 450 ms. The gain grows as dependent call chains lengthen and the network slows; on a simple screen that reads a single resource there is none.
Data volume shows a similar picture. REST responses return whole objects, and the four responses total 12 KB; the screen shows only 3 KB of fields. The unnecessary data is 12 − 3 = 9 KB, which is 9 ÷ 12 = 75%. With 40,000 screen opens a day, that is 40,000 × 9 KB = 360,000 KB ≈ 360 MB per day and ≈ 10.8 GB over 30 days. On a slow mobile network the gap also shows up in time.
What Is the N+1 Problem and How Does Batched Loading Solve It?
N+1 means running 1 query for a list and then a separate query for each item in the list. It is an easy mistake in GraphQL because every field has its own resolver, which runs separately for each list element.
In a query for 100 orders, if each order's customer is read separately, 1 + 100 = 101 database queries run. At an assumed 3 ms per query that is 101 × 3 = 303 ms; the 30 ms resolution share on the server grows to 303 ms and the single query's gain melts away. If the line items of the orders are read the same way, it becomes 1 + 100 + 100 = 201 queries and 201 × 3 = 603 ms.
The solution is batched loading (the data loader concept): the IDs that accumulate within the same request are collected into one query. In the example, the 100 orders have only 38 distinct customers; the 62 repeated IDs are not read again and the customers arrive in one query. The query count falls to 1 + 1 = 2 and the time to 2 × 3 = 6 ms. With line items as well, it is 1 + 1 + 1 = 3 queries and 9 ms. For how an index speeds up queries, see our database indexing guide.
How Are Query Depth and Cost Limited?
Because the client writes the query itself, a single query can strain the server. That is why limits are set on depth, object count and total cost.
A simple cost model: every resolved object is 1 point; in a list, the object count is the requested first N. If the query is "first 50 orders, the first 20 line items of each, the product of each line item", the object count is 50 + 50 × 20 + 1,000 = 50 + 1,000 + 1,000 = 2,050 points. With a 1,000-point budget the query is rejected before it runs. The same screen with "first 25 orders, first 10 line items" costs 25 + 250 + 250 = 525 points and passes.
| Query | Calculation | Points | Result (budget 1,000) |
|---|---|---|---|
| First 25 orders, first 10 line items, product | 25 + 250 + 250 | 525 | Runs |
| First 50 orders, first 20 line items, product | 50 + 1,000 + 1,000 | 2,050 | Rejected |
| 4 levels in a circular schema, first 20 at each level | 20 + 20² + 20³ + 20⁴ = 20 + 400 + 8,000 + 160,000 | 168,420 | The depth limit also kicks in |
Why the third row matters: in a schema with mutual relations such as order → line item → product → line items → order, a client can write a nearly endless nested query. That is why a depth limit (for example 5) and a cost budget are used together. The rate limit is also kept in cost points rather than request count: an allowance of 60,000 points per minute means 60,000 ÷ 525 ≈ 114 queries for a 525-point query and 60 queries for a 1,000-point query. We covered the general framework for rate limits and quotas in our API key and quota guide.
A public GraphQL API can take one more step: allow only pre-registered queries to run (an allowlist of queries). The client sends the ID of the registered query instead of the query text. This also saves bandwidth: a 64-byte ID instead of 2,000 bytes of query text saves (2,000 − 64) × 1,000,000 = 1,936,000,000 bytes ≈ 1.9 GB at 1,000,000 requests a day.
How Are Authorization and Schema Introspection Secured in GraphQL?
Because GraphQL has a single endpoint, "who can reach this address" is not enough; authorization must be applied at the field and object level, inside the resolver. The rule is the least-privilege principle of role-based access control; details are in our role-based access control guide.
| Field | Dealer | Warehouse | Accounting | Manager |
|---|---|---|---|---|
| order.status | Own orders only | Yes | Yes | Yes |
| order.total | Own orders only | No | Yes | Yes |
| product.cost | No | No | Yes | Yes |
| customer.credit limit | No | No | Yes | Yes |
Two separate checks are needed: object level (a dealer sees only their own orders) and field level (a dealer can never see the cost field). What happens to a client that queries an unauthorized field is decided up front: the field returns empty and an error is logged, or the query is rejected. Leaving the rule to the client amounts to hiding the field on screen; the data still travels over the network. For general API security principles, see our API security guide.
Schema introspection is the schema's ability to describe itself and is very valuable in development. In production on a public API, switching it off or tying it to authorization is a common choice so as not to hand an attacker a map of the schema. This alone is not security; the real protection is authorization, cost limits and input validation. To give the schema to partners as documentation, see our API documentation guide.
Why Is Caching Hard in GraphQL?
In REST every resource has its own address; browsers, networks and intermediate layers cache by address. In GraphQL, requests usually go to a single address with different bodies, so ready-made address-based caching does not work and caching moves into the application.
- Client side: Objects are stored by ID; an order read on one screen is reused on another.
- Registered query: Queries called by ID can again become suitable for address-based caching.
- Field-level cache: Expensive fields are kept briefly inside the resolver; staleness time and invalidation rules are written up front.
- User-specific data: Permission-dependent fields do not enter a shared cache; otherwise data leaks to the wrong user.
We covered cache layers in our caching guide. In an API where most users receive the same data, this difficulty is the biggest objection to moving to GraphQL.
GraphQL or REST? A Six-Question Test
Answer the questions below for the candidate API. Each "yes" is one point in favor of GraphQL.
- Do several clients (web, mobile, partners) want different sets of fields from each other?
- Do screens need nested, related data (order, line item, product)?
- Does sequential call latency on mobile networks really cause problems?
- Is the team ready to manage a schema, resolvers, batched loading and a cost limit?
- Does critical speed not depend on single-address HTTP caching?
- Is the API mostly consumed by your own clients rather than uncontrolled third parties?
| Number of "yes" | Meaning | Recommended step |
|---|---|---|
| 5–6 | GraphQL is a strong candidate | Run a pilot for a single screen |
| 4 | Suitable, watch the risks | Run a pilot, design the cost limit up front |
| 2–3 | Mixed picture | Compare with field selection and a combined endpoint in REST |
| 0–1 | REST is enough | Improve REST; GraphQL is not needed |
For a public, resource-oriented, cache-friendly partner API, the result is often in favor of REST. On versioning and compatibility, GraphQL's add-fields-and-deprecate approach is convenient; we covered the rules in our API versioning guide.
How Much Does a GraphQL Layer Cost and When Does It Pay Back?
The payback comes from fewer "new endpoint for a screen" requests from the mobile and web teams. The assumptions below are illustrative.
- Investment: 40 person-days × ₺9,000 = ₺360,000 for the schema, resolvers, batched loading, cost limit and monitoring.
- Current load: 6 new endpoint requests a month × 1.5 person-days = 9 person-days × ₺9,000 = ₺81,000.
- After GraphQL: Requests fall from 6 to 2; the remaining 2 × 1.5 = 3 person-days × ₺9,000 = ₺27,000. The gain is ₺81,000 − ₺27,000 = ₺54,000 per month.
- Operations: ₺14,000 a month for schema management, monitoring and batched-loading upkeep.
| Item | Calculation | Amount |
|---|---|---|
| Monthly gain | ₺81,000 − ₺27,000 | ₺54,000 |
| Monthly operations | Schema, monitoring, upkeep | ₺14,000 |
| Monthly net | ₺54,000 − ₺14,000 | ₺40,000 |
| Payback | ₺360,000 ÷ ₺40,000 | 9 months |
| If the gain is halved | (₺27,000 − ₺14,000 = ₺13,000) ₺360,000 ÷ ₺13,000 | ≈ 27.7 months |
If the monthly gain falls below ₺14,000, the layer never pays for itself. This calculation does not put a price on the speed gain; that benefit should be confirmed by measurement. To measure the load, see our performance testing guide.
How Is a GraphQL Project Run?
- List the screens: Measure which screen gets which fields with how many calls.
- Design the schema in business terms: Do not expose database tables as they are.
- Set up batched loading from the start: Measure the query count for every related field.
- Set depth and cost limits: Start strict and loosen with measurement.
- Test field-level authorization: Keep the fields each role sees in a table.
- Pilot on a single screen: Measure latency, data volume and query count before and after.
What Are Common GraphQL Mistakes?
- Allowing unlimited queries: GraphQL without depth and cost limits hands even your own client a denial-of-service tool.
- Checking authorization only at the endpoint: Without field-level rules, data leaks easily.
- Not measuring N+1: A field that looks fast with 5 records in development slows down at 100.
- Looking for errors only in the HTTP status: In many setups a partial error also arrives with a successful response; monitoring must be tuned for this.
- Choosing GraphQL for every need: Simple, cache-friendly resources are simpler with REST.
We recommend reading: What is an API gateway? Added latency, caching and payback guide
We recommend reading: What is microservices architecture? Monolith difference, cost and decision guide
We recommend reading: What is software scalability?
API and Integration Development with İnovabil
At İnovabil, our focus is building bespoke software from scratch for your company: custom software, ERP, CRM, e-commerce, web, mobile and integration. For the API layer, we suggest deciding together which approach fits by writing down the screens, clients and expected load in the requirements analysis; often a plain, well-documented API is enough. We recommend GraphQL only when a measurable need justifies it.
We built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; and warehouse management with a complaint and support management system for Sleepy. In these projects, integration, permissions and role structure are core parts of the system. If you are designing an API for a mobile app, also see our mobile app guide; briefly describe your screens and clients, and let us produce a written assessment together.
We recommend reading: Our software development process: from analysis to launch, step by step
Frequently Asked Questions
What is GraphQL, and what is it for in short?
It is an API query language in which the client states in a single query which fields it wants and the server returns only those. It lets you fetch related data in one call and lets each screen choose its own set of fields.
Is GraphQL faster than REST?
Not always. It is faster when it reduces several dependent calls to one query and cuts excess data; in the example 640 ms falls to 190 ms and 12 KB to 3 KB. On a simple screen that reads a single resource there is no gain, and it can slow down because of N+1 or unlimited queries.
What is the N+1 problem in GraphQL?
It means running one query for a list and then a separate query for each item. With 100 orders, 1 + 100 = 101 queries run. Batched loading, which collects IDs within the same request, reduces this to 1 + 1 = 2 queries.
Is GraphQL secure?
It is neither secure nor insecure on its own; security depends on the implementation. Field-level authorization, depth and cost limits, input validation and restricting schema introspection in production are the basic measures. A setup that allows unlimited queries can strain the server easily.
When should you move to GraphQL and when stay with REST?
If many different screens need nested data and latency on mobile networks causes problems, GraphQL is worth considering. For a public, cache-friendly, resource-oriented partner API, REST is usually simpler and less risky. Run the six-question test and the payback calculation with your own figures.