GraphQL

Updated on Jan 23, 2025

While the next section of the Craft CMS dashboard is GraphQL, we will not cover it extensively in this tutorial. As it is for beginners, we will explain what GraphQL is used for and what it can do for applications created with Craft, but we will not go beyond that. Its usage requires a whole other set of skills and knowledge, which are not absolutely necessary to get started with Craft CMS. 

GraphQL is an open-source query language and server-side runtime for APIs as an alternative to REST. If those words don’t make sense, do not worry; we will explain.

  • Query Language - A query language is a computer language used to make queries in databases and information systems. It allows users to request specific information, perform searches, and retrieve data by specifying criteria the data must meet. Query languages are designed to work with structured data and are typically part of a database management system. An example of a query language is SQL, which you might know from MySQL - the database management system;
  • Server-side Runtime - Server-side runtime refers to the environment on a server that executes server-side scripts or programs. The runtime has the necessary infrastructure and services for those scripts or programs to work correctly and for processing requests from external sources such as web browsers. An example of a runtime environment like that is Node.js;

Simply put, GraphQL is a technology that allows you (your application) to ask for specific information from a database or server. What differentiates it from other query languages is that it uses specific queries to request only the precise data you require instead of fetching more or less of what you need. The server will return only what it is asked for. Because of that, GraphQL is used for building APIs, which are different ways for applications to communicate with each other - to send the requested data back and forth. 

When compared to other query languages (such as REST or SQL), GraphQL offers several advantages.

  • Specificity and Efficiency - With GraphQL, you can precisely find and fetch the data you need with a single request. REST, on the other hand, requires multiple requests and often returns more data than requested;
  • Flexibility - While REST relies on more rigid endpoint definitions, GraphQL offers a more flexible way of obtaining data. It can request nested and related data in a single query instead of having to use multiple like REST, as we mentioned above;
  • API Query Language - Unlike a typical query language like SQL, which operates solely in the database layer of an application, GraphQL sits between the server and the application. That way, it can more easily, efficiently, and directly query data from the server’s data model or management system.

As you can see, GraphQL is a data-fetching mechanism for APIs, but it also provides the flexibility and specificity of a database-layer language like SQL. It combines aspects of both technologies that make it stand out. If you would like to learn more about it, we strongly recommend its documentation.

On this page...