Blogs
Jason Smith
Chief User Experience Officer
Image Credit: Marvin Meyer

dotCMS: The Headless CMS for GraphQL

Aug 30, 2021
By: Jason Smith

There is no doubt that REST APIs have become the standard over the years. REST indeed makes things simpler for developers and provides a way of mapping HTTP verbs and controller CRUD actions. 

However, GraphQL has been making a name for itself since its inception in 2012. GraphQL is designed to make APIs more flexible and developer-friendly than REST; but, above all, it aims at making API calls faster. 

GraphQL represents a new way of thinking about APIs and can transform web development by enabling seamless communication between the front and the backend. 

When used in conjunction with a headless CMS, GraphQL shows its true strengths, simplifying omnichannel content delivery. This article shows you what a headless CMS for GraphQL can do for your business and shows you why dotCMS is the CMS for you.

What is GraphQL?

According to its creators, GraphQL is "a query language for APIs and a runtime for fulfilling those queries with your existing data." Facebook developed GraphQL in 2012 as an alternative to REST that lets developers construct requests that pull data from multiple sources in a single API call, which makes it perfect for the omnichannel content delivery the headless architecture proposes.

GraphQL gives developers the flexibility to add or deprecate fields without impacting existing API queries. Also, developers can build APIs with the methods of their liking, and GraphQL will make sure they act predictably for clients. 

GraphQL aims at solving the inefficiencies that web developers encounter when fetching data from various sources. With GraphQL, developers can send a single query to the server and then the server returns with JSON points. Once this operation reaches the backend, it's then fixed with the frontend data application. 

Benefits of GraphQL

GraphQL Makes API Requests More Efficient

Client-side applications built on top of REST APIs need many subsequent requests to fetch data, resulting in a slow response time and a poor user experience. With GraphQL you can retrieve information about, let's say, a blog article along with the article's metadata in a single request. Similarly, GraphQL requires developers to add the desired resource field to every query, eliminating the need for over-fetching data. 

GraphQL Has Superior API Exploration

Thanks to GraphQL, GraphQL gains superior API exploration. GraphQL lets developers construct queries iteratively, which means that as developers type a query, suggestions for auto-completion will appear, simplifying query building and reducing the possibility of typing a bad query.

GraphQL Has a Solid Tooling Ecosystem

GraphQL is growing at a breakneck speed because it is easy for developers to use it to query data faster. Also, since JavaScript is the most common language used with GraphQL, the majority of the tools and software made for the GraphQL ecosystem integrate with it, making it a solid choice for JAMstack developers. However, GraphQL can be used with almost every programming language out there and supports different ways of creating APIs.

Now that we've discussed some of the benefits of GraphQL let's talk about how it integrates with a headless CMS

Why Choose a Headless CMS for GraphQL?

Omnichannel content delivery is the new standard for CMS content delivery. Companies use a myriad of touchpoints to interact with users and customers. While robust for many uses and still going strong, REST API isn't great at enabling omnichannel content delivery. 

A headless CMS like dotCMS supports GraphQL natively, empowering developers to query every content type as a collection, including HTML, categories, and personas. dotCMS enables developers to build and support an increasing number of channels, from IoT-ready devices to single-page applications and progressive web apps. 

dotCMS' support of GraphQL enables developers to perform queries across the entire content repository in a similar way to Elasticsearch to generate a schema. No additional coding is needed, and your instance will automatically return your results based on your specific requirements. 

Take a look at how GraphQL and dotCMS bring benefits to different user types: 

  • GraphQL for Businesses: When coupled with dotCMS, GraphQL results in better performance for the end customer because the frontend doesn't have to make and handle as many requests because GraphQL makes parallel requests and delivers that data to the frontend in a single document.
  • GraphQL for Developers: GraphQL simplifies API design and development and eliminates the need for API versioning, removing the need to maintain multiple versions of the API.
  • GraphQL for Content Editors: GraphQL simplifies content creators' lives and enables them to assemble content from different sources and deliver it with the exact frontend requirements, all with a single API call.  

Thanks to GraphQL, dotCMS' customers unify content and third-party tools that are isolated across the company into a single, centralized content hub to help content creators and developers deliver content across multiple digital channels and customer touchpoints. 

These are some of the ways GraphQL supports and enhances the operations of a headless CMS

Simplified Messaging Between Channels

While every channel and device has its own lifecycle, often built differently from one another, GraphQL supports dotCMS by giving it a general, standard set of APIs that enables communication between different platforms and third-party tools. 

Also, a GraphQL-native CMS like dotCMS can benefit from its extensive language support, which enables developers to leverage the same APIs across a wide range of technology. Plus, the declarative nature of GraphQL allows for increased granularity and support of channel-specific needs without the need for extra code.  

Enhanced Standardization

Since GraphQL is a general API that sits on top of any datastore, it can be used to create a unified API entry point for your company, which enables developers to standardize their API operations. 

With GraphQL, standardization of both interfaces, versioning, security, and monitoring is possible. It provides developers with a solid starting point for standardization to prevent a mishmash of API services that endanger your operations. 

Easy To Combine With Other Data Sources 

A headless CMS houses many different content types. Product data, inventory data, customer data, and so on. Without GraphQL, connecting every dot is a time-consuming task that results in a cumbersome user experience. With GraphQL, your digital experiences can request content and marry your content types with other different, relevant data sources in a consistent way, tailored to customers' and users' needs.

GraphQL and dotCMS: Supporting Omnichannel Content Delivery

GraphQL is the fuel and the bridge that makes all those innovations possible, especially in JAMstack development. GraphQL has become a game-changing tool in the headless CMS ecosystem with features such as self-documenting and declarative data fetching.

The benefits of GraphQL for dotCMS' users are many. For instance, with GraphQL, frontend developers don't have to worry about searching for individual data points and determining the exact source of truth. 

On the contrary, GraphQL APIs act as a single source of truth and can be embedded into the business logic, reducing the amount of time developers spend looking for the source, which also results in less code to maintain. 

GraphQL supports dotCMS' omnichannel content delivery capabilities and enables nimble data transmission across channels. GraphQL is perfect for modern developers looking for a lightweight technology that allows an increased granularity level without the need for coding on the data's source system. 

This, along with the benefits we've discussed in this article, has boosted the adoption of GraphQL across the software community, effectively dethroning REST as the champion of headless, omnichannel content delivery. 

If you're interested in going deeper into GraphQL and how you can simplify your content delivery, read our article on Using GraphQL to Simplify Headless Content Management

Filed Under:

Recommended Reading

14 Benefits of Cloud Computing and Terminology Glossary to Get You Started

What is cloud computing, and what benefits does the cloud bring to brands who are entering into the IoT era?

Headless CMS vs Hybrid CMS: How dotCMS Goes Beyond Headless

What’s the difference between a headless CMS and a hybrid CMS, and which one is best suited for an enterprise?

Exploring TimeMachine: How dotCMS Handles Content Versioning

With dotCMS, tools like TimeMachine and Workflow Management help enterprises control content versioning, content edits, user permissions, workflows and more.