Frequently Asked Questions

Product Information & Technical Details

What is Hygraph and how does it relate to Next.js dynamic routing?

Hygraph is a GraphQL-native Headless CMS designed to empower teams to build better digital experiences. In the context of Next.js, Hygraph can serve as the backend for dynamic routing, providing structured content via APIs that Next.js can use to generate pages dynamically at build time or runtime. This enables developers to create scalable, performant applications with features like static site generation and server-side rendering. (Source)

Does Hygraph provide APIs for integrating with Next.js?

Yes, Hygraph offers a variety of APIs, including a GraphQL Content API for querying and managing content, a GraphQL Management API for schema changes, and REST APIs for broader integration. These APIs are designed to work seamlessly with frameworks like Next.js, enabling dynamic routing and content-driven applications. (Documentation)

What technical documentation is available for Hygraph?

Hygraph provides comprehensive technical documentation, including API references, guides for integrations (such as Next.js), content workflows, and webhooks. Interactive API playgrounds are also available for hands-on exploration. Access all resources at the Hygraph Documentation Page.

Features & Capabilities

What are the key features and capabilities of Hygraph?

Hygraph offers Smart Edge Cache for fast content delivery, Content Federation to integrate data from multiple sources, advanced Rich Text formatting, Custom Roles for granular access control, and Project Backups for data safety. It is developer-friendly, supports seamless integrations, and is compliant with SOC 2 Type 2, ISO 27001, and GDPR standards. (Features)

What integrations does Hygraph support?

Hygraph integrates with a wide range of platforms, including digital asset management (Aprimo, AWS S3, Bynder, Cloudinary, Mux, Scaleflex Filerobot), hosting and deployment (Netlify, Vercel), eCommerce (BigCommerce, commercetools, Shopify), localization (Lokalise, Crowdin, EasyTranslate, Smartling), personalization (Ninetailed), AI (AltText.ai), and more. (Integrations Documentation)

How does Hygraph perform in terms of speed and scalability?

Hygraph leverages state-of-the-art caching and edge services for low latency and high read-throughput, supporting rapid content delivery worldwide. Customers have reported 7X higher content velocity, 125% traffic growth, and support for 40+ global markets and 100+ stakeholders. (Source)

Use Cases & Benefits

Who can benefit from using Hygraph?

Hygraph is ideal for developers, IT decision-makers, content creators, project managers, agencies, and technology partners. It serves modern software companies, enterprises, brands scaling across geographies, and organizations re-platforming from legacy solutions. (Case Studies)

What industries are represented in Hygraph's customer case studies?

Hygraph's case studies span eCommerce, automotive, healthcare, consumer electronics, media and publishing, food and beverage, travel and hospitality, engineering, government, and SaaS. Examples include Samsung (consumer electronics), Dr. Oetker (food), Komax (engineering), and HolidayCheck (travel). (Case Studies)

What business impact can customers expect from using Hygraph?

Customers have reported up to 3X faster time-to-market (Komax), 15% higher customer engagement (Samsung), 20% increase in website monetization (AutoWeb), 7X higher content velocity, and 125% traffic growth. Hygraph supports scaling across 40+ global markets and 100+ stakeholders. (Case Studies)

Can you share specific customer success stories?

Yes. Komax achieved 3X faster time to market and managed 20,000+ product variations across 40+ markets. Samsung saw a 15% increase in customer engagement. Dr. Oetker ensured global consistency with MACH architecture. Sennheiser increased e-commerce conversions by 136.7% in 4 months. Stobag improved online revenue share from 15% to 70%. (Case Studies)

Pain Points & Solutions

What problems does Hygraph solve for businesses?

Hygraph addresses operational inefficiencies (removing developer bottlenecks, improving workflows), financial challenges (reducing costs, accelerating speed-to-market), and technical issues (simplifying schema evolution, cache management, and integration with multiple endpoints). It also helps unify global marketing needs and modernize legacy tech stacks. (Content Federation)

What pain points do Hygraph customers commonly express?

Customers often face bottlenecks due to developer-dependent content updates, outdated legacy systems, high operational costs, slow speed-to-market, limited integration capabilities, and technical challenges with evolving schemas and cache issues. Hygraph provides solutions to streamline operations and reduce these pains. (GraphQL Survey)

Ease of Use & Implementation

How easy is it to get started with Hygraph?

Hygraph is recognized as the #1 easiest to implement headless CMS. Customers can start building for free with a developer account, and enterprise users can request a demo. The onboarding process includes introduction calls, account provisioning, business and technical kickoffs, and content schema planning. (Try Hygraph)

How long does it take to implement Hygraph?

Implementation is fast. For example, Top Villas launched a new project with Hygraph in just 2 months from initial touchpoint to launch. Si Vale met aggressive deadlines with a smooth initial implementation phase. (Top Villas Case Study)

Is Hygraph easy for non-technical users?

Yes, Hygraph is praised for its intuitive user interface and logical workflows, making it accessible for non-technical users. The editor UI is clear, and customization features are easy to use. Content editors and developers can collaborate effectively. (Try Hygraph)

Support, Maintenance & Training

What customer support is available after purchasing Hygraph?

Hygraph provides 24/7 support via chat, email, and phone. Enterprise customers receive SLAs for critical issues (resolved in less than an hour), onboarding assistance, a dedicated Customer Success Manager, and access to documentation, community Slack, and Intercom chat. (Pricing)

How does Hygraph handle maintenance, upgrades, and troubleshooting?

Hygraph's cloud-based infrastructure handles all maintenance, server updates, and security patches. Upgrades are automatic, and troubleshooting is supported by audit logs, monitoring, and performance reporting. Customers have access to 24/7 support and extensive documentation. (Documentation)

What training and technical support is available to help customers get started?

Hygraph offers onboarding support (introduction call, account provisioning, business/technical/content kickoffs), training resources (documentation, webinars, live streams), and technical support (24/7 chat/email/phone, community Slack, Intercom chat, and support SLAs for enterprise customers). (Onboarding Overview)

Security & Compliance

What security and compliance certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications ensure robust data protection and adherence to industry standards. (Security Features)

How does Hygraph ensure data security and compliance?

Hygraph uses granular permissions, audit logs, encryption at rest and in transit, SSO integrations, automatic backups, and offers dedicated hosting and custom SLAs for enterprise-grade compliance. Security incidents can be reported, and a public security and compliance report is available. (Security Report)

Customer Proof & Recognition

Who are some of Hygraph's customers?

Hygraph is trusted by leading brands such as Sennheiser, HolidayCheck, Ancestry, JDE, Dr. Oetker, Ashley Furniture, Lindex, Hairhouse, Komax, Shure, Stobag, Burrow, G2I, Epic Games, Bandai Namco, Gamescom, Leo Vegas, Codecentric, Voi, and Clayton Homes. (Case Studies)

See Hygraph MCP Server, AI Agents, and Editorial Experience Upgrades in Action

Dynamic Routing in Next.js

As part of this tutorial, you will learn how to set up dynamic routing in Next.js, including pre-rendering, server-side rendering, and static generation.
Aagam Vadecha

Last updated by Aagam 

Sep 16, 2024

Originally written by Hygraph

Dynamic Routing in Next.js

#Pre Rendering

Next.js is a hybrid framework on top of React, which enables static and server-side rendering. It is packed with awesome features like file system routing, dynamic routing, image optimization, typescript support, code-splitting & bundling, etc., which are useful for any project. All in all, it is an impressive production framework for React.

When a page is loaded by the browser (client), its JavaScript code runs, making the page fully interactive. In addition to client-side rendering, Next.js offers pre-rendering for your views, which means that the HTML is generated in advance by Next.js and it need not rely on the client-side Javascript.

Pre-rendering can happen in two ways

  • Server-side
  • Static Generation

Server Side Rendering

When we cannot pre-render a page’s view ahead of a user's request, i.e in cases where we need to check the request and respond accordingly with a dynamically up-to-date page, we can either use server-side rendering or client-side rendering, as the data on the page depends on the request.

In server-side rendering, the request is received from the client, the server then generates the HTML and sends it back to the client. So here, the server generates the HTML for each request.

Diagram of the Server-Side Rendering (SSR) flow, where the server generates HTML in each request

Static Generation

When the data on a page is static, i.e. it doesn’t matter who is requesting, the response will always be the same. For instance, for a blog post, it doesn’t matter who requests it, it would always deliver the same content.

Since we have to deliver the same page, we can pre-render it during build time i.e statically generate it. This will result in faster responses than client-side or server-side rendering as the HTML page is generated at the build time itself and not run time.

In the case of a blog application, our static frontend pages in a Next.js App can be structured as below

/pages/post/post1.js
/pages/post/post2.js
/pages/post/post3.js

When we run the next build command, these pages will be statically generated once and the same copy can be quickly served to the users every time.

Diagram showing Static generation, where next build creates HTML at build-time to be reused for each request

Now let’s say that we want to add 10 more blogs, one option to do so is to create additional static react components for each and every blog like post4.jsx, post5.jsx, post6.jsx, and so on, and then build and deploy it. One caveat with this approach is that it will probably duplicate the same code over and over, and create additional components. This is not a neat scalable solution, imagine the code directory of a blog site with thousands of blogs built with this approach.

We need a way to dynamically generate any number of routes and we need to do that at build time in order to serve statically pre-rendered pages. Next.js supports dynamic routing which helps us to achieve this kind of use case. Let us try to learn more about dynamic routing with the help of an example.

#Example

Use Case

We want to build a simple frontend blog application, it should use Static Site Generation in a way that it will dynamically create any number of routes (example: post/1, post/post2, post/3, ... post/n). The number of routes can vary and can come from an external data source (eg: a database), The pages should be statically generated at build time, so we do not have to server side render them on run time. We assume that you are comfortable with the basics of Next.js and React and that you have a Next.js app up and running.

If you are not familiar with Next.js, we recommend you to go through some articles below and get started.

Mocking API Data

Let us create two simple functions that will provide data to our application. For demo purposes we have mocked data in this frontend itself. In a real-world application, you would want to replace this dummy data with actual API calls to get data from your data source.

First, add a function getPostIdList() that will return the list of posts in the format below.

lib/posts.js

export async function getPostIdList() {
return [{
params: {
id: '1'
}
}, {
params: {
id: '2'
}
}, {
params: {
id: '3'
}
}]
}

Two important things to note here are:

  • The response array should have the same format as shown above, this will help next.js to generate paths for our routes dynamically. We used id as our inner key since we will be creating our dynamic route component ahead as pages/post/[id].js .If our dynamic route component would have been /pages/post/[postId].js, we would use postId as the key here.
  • Next.js requires the value corresponding to the id key to be always a string.

Now, let's add another function getPostDetails() that will return some dummy data for each post.

lib/posts.js

export async function getPostDetails(postId) {
const dataSet = {
'1': {
title: 'Post 1',
description: 'Lorem ipsum dolor sit amet...',
date: 'Oct 10, 2022'
},
'2': {
title: 'Post 2',
description: 'Lorem ipsum dolor sit amet...',
date: 'Oct 20, 2022'
},
'3': {
title: 'Post 3',
description: 'Lorem ipsum dolor sit amet...',
date: 'Oct 30, 2022'
}
}
return dataSet[postId]
}

Adding a Dynamic Route Component

We want to display our blog on routes like /post/1, /post/2, etc. In Next.js, we can create a dynamic segment by wrapping file or folder name in square brackets like this [segmentName] . For our use case let us create a dynamic route component at pages/post/[id].js, any request in the browser like /post/1, /post/2, /post/a will match to this page.

Since each of our posts will have 3 fields - title, description, and date, we can render this simple template.

pages/post/[id].js

export default function Post({ postData }) {
return (
<div className='bg-gray-800 h-screen p-16 text-gray-100'>
<div className='text-center font-bold text-3xl'>
{postData.title}
</div>
<div className='text-justify my-8 text-gray-200'>
{postData.description}
</div>
<div className="text-gray-400">
Published On: {postData.date}
</div>
</div>
);
}

getStaticPaths and getStaticProps

We have our data ahead of users request and we need to pre-render our component at build time. Our component expects a postData prop, we just need a way to provide this prop to our component at build time.

getStaticProps method from Next.js allows us to do this. Let us add it to our component as shown below

export async function getStaticProps({ params }) {
const postData = await getPostDetails(params.id);
return {
props: {
postData,
},
};
}

We expect getStaticProps function to get the route parameters as an input. It can then use that post id and our mocked API function getPostDetails to get postData. Then it returns the postData in the format shown above. That’s it, Next.js will ensure our component function will get the postData prop.

Whenever we use dynamic routes and getStaticProps. We will need to also use getStaticPaths method provided by Next.js. When we export a function called getStaticPaths (Static Site Generation) from a page that uses dynamic routes, Next.js will statically pre-render all the paths specified by getStaticPaths. Also, in the above code getStaticProps is expecting params object which contains the post id that is needed to retrieve the post data. getStaticPaths can also be used to provide the params object to getStaticProps. Let us use it as shown below:

pages/post/[id].js

import { getPostDetails, getPostIdList } from '../../lib/posts';
export async function getStaticPaths() {
const paths = await getPostIdList();
return {
paths,
fallback: false,
};
}

getStaticPaths() gets the list of paths from our mocked API function getPostIdList() and Next.js will generate the respective routes and also pass the context ahead to getStaticProps.

In production, both getStaticProps and getStaticPaths will run only at the server at build time, it will not run on runtime.

Below is our final component

pages/post/[id].js

import { getPostDetails, getPostIdList } from '../../lib/posts';
export async function getStaticPaths() {
const paths = await getPostIdList();
return {
paths,
fallback: false,
};
}
export async function getStaticProps({ params }) {
const postData = await getPostDetails(params.id);
return {
props: {
postData,
},
};
}
export default function Post({ postData }) {
return (
<div className='bg-gray-800 h-screen p-16 text-gray-100'>
<div className='text-center font-bold text-3xl'>
{postData.title}
</div>
<div className='text-justify my-8 text-gray-200'>
{postData.description}
</div>
<div className="text-gray-400">
Published On: {postData.date}
</div>
</div>
);
}

dynamic route 1 dynamic route 2

Blog Authors

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.