What is Hygraph FM and how does it work with Next.js?
Hygraph FM is a music platform project that demonstrates how to build artist and landing pages using Next.js 13 and federated content from Hygraph. The platform leverages Hygraph's content model and remote source integration (such as LastFM) to dynamically generate artist pages, homepages, and promotional blocks. This approach enables scalable, modular content management and rapid frontend development. Source
How does Hygraph FM use federated content and remote sources?
Hygraph FM connects to remote sources like LastFM to fetch artist metadata, including bios, tags, and similar artists. This federated content is integrated into the Hygraph content model, allowing for dynamic updates and avoiding duplication of data maintained in other systems. This setup reduces development time, increases flexibility, and maintains consistency across the platform. Source
What are the main steps to build artist pages with Hygraph FM and Next.js?
The main steps include: initializing a Next.js 13 project, setting up global styles, connecting Hygraph via the Content API, creating homepage and featured artist sections, generating dynamic artist summary pages using slugs, building a landing page for all artists, and implementing server components for promotional content (Callout and CTA). Each step is supported by code samples and leverages Hygraph's modular content model. Source
How does Hygraph FM handle promotional content and business goals?
Hygraph FM uses reusable promotional components, such as Callout and CallToAction, which are integrated into the artist content model. These components allow editors and marketers to create and display promotional messages and CTAs, supporting business objectives like user engagement and platform growth. The modular approach ensures scalability and easy modification when new features are needed. Source
Features & Capabilities
What are the key features of Hygraph for building modular content platforms?
Hygraph offers a component-based system that enables editors to create pages using reusable blocks, supports federated content from remote sources, and provides a GraphQL-native API for efficient data querying. The platform is designed for scalability, flexibility, and rapid development, making it ideal for building modular content platforms like Hygraph FM. Learn more
Does Hygraph support integration with other platforms and services?
Yes, Hygraph supports a wide range of integrations, including hosting and deployment (Netlify, Vercel), eCommerce (BigCommerce, Shopify), localization (Lokalise, Crowdin), digital asset management (Cloudinary, AWS S3), personalization (Ninetailed), and AI (AltText.ai). These integrations enable seamless workflows and extend platform capabilities. See full list
What API does Hygraph provide for content management?
Hygraph provides a powerful GraphQL API that allows developers to fetch and manage content efficiently. The API supports complex queries, federated data, and is well-documented for easy integration with frontend frameworks like Next.js. API Reference
How does Hygraph's component-based system improve publishing efficiency?
Hygraph's component-based system allows content elements to be reused across multiple pages, enabling interconnected content relations and improving publishing efficiency. Components do not count as entries but serve as a way of building pages flexibly and modularly. HolidayCheck Case Study
Technical Requirements & Documentation
Where can I find technical documentation for Hygraph and Hygraph FM?
Comprehensive technical documentation for Hygraph, including API references, integration guides, and tutorials, is available at Hygraph Documentation. This resource covers everything needed to build and deploy projects like Hygraph FM.
What are the minimum requirements to start building with Hygraph FM?
To start building with Hygraph FM, you need a Hygraph account, a LastFM account (for remote source integration), and a basic understanding of content modeling. The project setup involves initializing a Next.js 13 project and connecting it to Hygraph's Content API. Source
Performance, Security & Compliance
How does Hygraph optimize content delivery performance?
Hygraph emphasizes optimized content delivery performance, which directly impacts user experience, engagement, and search engine rankings. Rapid content distribution and responsiveness help reduce bounce rates and increase conversions. Learn more
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant, ISO 27001 certified, and GDPR compliant. These certifications ensure enterprise-grade security and data protection for users. Features include SSO integrations, audit logs, encryption at rest and in transit, and sandbox environments. Security Features
Pricing & Plans
What is Hygraph's pricing model?
Hygraph offers a free forever Hobby plan, a Growth plan starting at $199/month, and custom Enterprise plans. For detailed information on features and pricing, visit the Hygraph Pricing Page.
Support & Implementation
What support and training does Hygraph offer for new users?
Hygraph provides 24/7 support via chat, email, and phone. Enterprise customers receive dedicated onboarding and expert guidance. All users have access to documentation, video tutorials, webinars, and a community Slack channel. Customer Success Managers are available to assist during onboarding. Contact Hygraph
How easy is it to get started with Hygraph?
Hygraph is designed for ease of use, with an intuitive interface praised by customers. Non-technical users can start quickly by signing up for a free account and using onboarding guides and documentation. For example, Top Villas launched a new project in just 2 months. Documentation
Customer Success & Case Studies
Can you share specific case studies or success stories of customers using Hygraph?
Yes, Hygraph has several notable success stories. Komax achieved a 3X faster time to market, Autoweb saw a 20% increase in website monetization, Samsung improved customer engagement with a scalable platform, and Dr. Oetker enhanced their digital experience using MACH architecture. See more success stories
What industries are represented in Hygraph's case studies?
Hygraph's case studies span industries such as food and beverage, consumer electronics, automotive, healthcare, travel and hospitality, media and publishing, eCommerce, SaaS, marketplace, education technology, and wellness and fitness. Case Studies
Vision, Mission & Differentiation
What is Hygraph's overarching vision and mission?
Hygraph's vision is to unify data and enable content federation, empowering businesses to create impactful digital experiences. Its mission is to remove traditional content management pain points through a GraphQL-native architecture, taking Headless CMS to the next level. About Us
How does Hygraph differentiate itself from other CMS platforms?
Hygraph stands out with its GraphQL-native architecture, content federation, and scalability. It offers a component-based system for modular content creation, supports integrations with remote sources, and provides enterprise-grade security and compliance. These features enable faster speed-to-market, lower total cost of ownership, and control at scale. Product Page
In the first part of this series, we created an artist content model and components as well as connected LastFM as a remote source to get our music platform project, Hygraph FM. Now that these elements are in place, it’s time to put our content model into action!
In this article, we will build a frontend using Next.js 13 and federated content from Hygraph. To do this, we’ll create the artist summary pages to render the artist bio, genre tags, and similar artists. Additionally, we will create a home page that showcases featured artists, a landing page that lists all artists on Hygraph FM, and render our promotional block components.
To start, we need to initialize a new Next.js 13 project. Open up your terminal and navigate to where you want your project, then run the following command:
npx create-next-app hygraphfm
The interactive setup will ask you questions to configure your project. Initialize with the following answers:
Typescript: No
ESLint: Yes
Tailwind CSS: Yes
src/ directory: No
App Router: Yes
Import alias: No
Once the options are chosen, the CLI will install all the necessary pieces to run your Next.js site.
Once the installation completes, open the new Next project in a code editor of your choice. We need to adjust the default Tailwind styling that Next.js gives us from the installation.
Update the global CSS rules in app/globals.css to add the following extra styling but leave the file with the following Tailwind imports:
@tailwind base;
@tailwind components;
@tailwind utilities;
Additional Styling:
/* global.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
:root{
--foreground-rgb: 29, 33, 39;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}
@media(prefers-color-scheme: dark){
:root{
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 29, 33, 39;
--background-end-rgb: 29, 33, 39;
}
}
body{
color:rgb(var(--foreground-rgb));
background:linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
/* Add the following styling */
.background-radial-gradient{
background-color:hsl(218, 41%, 15%);
background-image:radial-gradient(650px circle at 0% 0%,
hsl(218, 41%, 35%) 15%,
hsl(218, 41%, 30%) 35%,
hsl(218, 41%, 20%) 75%,
hsl(218, 41%, 19%) 80%,
transparent 100%),
radial-gradient(1250px circle at 100% 100%,
hsl(218, 41%, 45%) 15%,
hsl(218, 41%, 30%) 35%,
hsl(218, 41%, 20%) 75%,
hsl(218, 41%, 19%) 80%,
transparent 100%);
}
.all-links > a{
text-decoration: underline;
}
.fm-mode{
mix-blend-mode: color-dodge
}
After adding a few global styles, we need to connect Hygraph to our Next project so that we can use the data from our artist content model.
To make Hygraph accessible to our Next.js project, we need to allow read permissions on the Content API. Head over to your project’s settings and click on API Access. To start, let’s set the public content API to its default. This will give us access to all the content in our models, including the remote data from LastFM to read into our Next project. From this same screen, copy the Content API endpoint URL.
Create a new file in the root of your project named .env.local and add the variable HYGRAPH_ENDPOINT.
This will be where we paste the endpoint URL we copied from Hygraph:
//.env.local
HYGRAPH_ENDPOINT=YOUR-URL-HERE
Now we can start our Next site and build our frontend. In the terminal, type the following command to run the project locally in a browser of your choice:
First, let’s build our header, navbar, and footer. In your app directory, create a new folder called components . In the components folders, create three files: Header.js, Footer.js, Navbar.js and add the following code respectively:
<pclassName="text-lg text-[hsl(218,81%,95%)]">Hygraph FM is a community of artists, producers, listeners who are passionate about music and the creative process!
</p>
</div>
</div>
</div>
</div>
</header>
)
}
Navbar
// Navbar component: app/components/Navbar.js
'use client';
importHeadfrom'next/head';
importLinkfrom'next/link';
import{ useState }from'react';
exportdefaultfunctionNavbar(){
const[navbar, setNavbar]=useState(false);
return(
<navaria-label="Hygraph FM Menu"role="navigation"className="w-full bg-gray-800 shadow">
Note: Since we are using state, the Navbar is no longer a server component like the Header and Footer. It is now part of the client bundle. As a result, we need to add the ‘use client’; directive at the top of the file to denote this change.
Now that we have these components in place, we are ready to create our homepage with featured artists.
Querying recent artists for featured artist content
On our homepage, we want to provide a curated selection of artists for our users. To achieve this, we can create a section showcasing featured or recently added artists on our platform.
To implement this feature, we can send a query to Hygraph using the last operator, which allows us to retrieve the latest additions to our platform. By requesting the last six artists added, we can display them in a dedicated, appealing content section on our homepage.
# GraphQL query to get the 6 most recent artists from Hygraph
queryArtists{
artists(last:6){
slug
artist
id
artistImage{
altText
url
height
width
}
}
}
In the app directory, go to the file called page.js , delete everything and paste in the following code:
The above code makes a request to Hygraph gives us the name, slug, and image information for the last 6 artists from our artist content. This data is then rendered in a function that creates the Homepage.
Featured artist content will not only enhance the user experience by providing them with a selection of artists they may be interested in, but it will also help promote new artists and encourage users to explore the platform.
Great job! We now have a functional homepage for the Hygraph FM site, complete with featured artists that link to their individual bio pages. However, these links currently return a 404 error because the pages have not been created yet. Let's create them now!
To create individual pages for each artist on our platform, we need to establish a dynamic route to generate a unique page for every artist based on their slug. This allows us to provide content for each artist on our platform.
We will add a new directory called artist/[slug] in the app directory. Next, add a page.jsx file in your new artist/[slug] directory, which will serve as the template for each individual artist page. We will use this template to dynamically generate unique content for each artist based on their slug.
By creating a dynamic route for each artist, we can provide a more personalized experience for users on our platform. This will help to increase engagement and improve overall user satisfaction.
app/
┣ artist/
┃ ┗ [slug]/
┃ ┗ page.jsx
The structure of your project should match the file tree above. The [slug] new directory allows us to use our page.jsx as a file template to make a page for every artist. In the artist/[slug]/page.jsx file, add the following code:
Let’s breakdown this code down a bit. At the top of the file, we have an async function to fetch an artist by slug. The getArtist function fetches the artist data from Hygraph using the provided slug. Our content and remote data from LastFM is federated into a single API call that allows us to generate metadata for each artist dynamically. The Artist function is the template for each individual artist page and uses the getArtist function to retrieve and render the artist data. The page displays the artist's name, image, biosummary, similar artists, and tags.
To create a landing page that shows all artists on the platform, we need to create a new directory route in our app directory called artists . Create a new file called page.jsx inside the artists directory. Notice a pattern? In Next.js 13, page.jsx acts as file templates and the directory denotes what the route should be called when using the app router. In our case, this will contain the code to display all artists on the platform in a grid format.
/* File tree with artist
landing page template */
app/
┣ artist/
┃ ┗ [slug]/
┃ ┗ page.jsx
┣ artists/
┃ ┗ page.jsx
Add the following code in the artists/page.jsx file:
// Landing page for all artists: app/artists/page.jsx
In the above code, we create an async function called getAllArtists(). This function contains a GraphQL query that fetches all of the artists from Hygraph. The response will be returned as a JSON object, which we can loop through and display in our grid.
Once we have fetched all of the artists, we can then render them in our grid using the map() function. This function allows us to loop through each artist and display their information in a card-like format.
Our HygraphFM project now has a homepage and landing page for artists, and we created individual artist pages that display a bio, image, tags, and similar artists using a dynamic route in the app directory. We are almost done with our Next build! The last thing we need is to create server components to render our promotional content to help fulfill our organization’s business goals. We will start with creating the Callout server component.
In part 1 of this series, we built Button, Callout, and CTA components in Hygraph. These components will help content editors, and marketers create content for promotional and engagement campaigns. We added these components as a collection or modular component to our Artist content model, enabling us to create frontend code to display these content areas.
Making a Callout component
To implement a Callout component, we need to create a file named Callout.js inside the components directory. This component will render a promotional message with a button to invite new users to join Hygraph FM.
The Callout component takes two props: button and title. The title prop is the main text of the message, while the button prop is an object with two properties: text and url.
The Callout is ready to use in our application to promote our content and increase user engagement.
Call to Action (CTA) component
To create the CTA component, we need to create a new file in the components directory called CallToAction.js.
Let’s break down the code a bit. The CTA component takes several props, including body, heading, button, and image. These are the same field types we used when we created the CTA component in Hygraph. The body prop will contain the body text of the CTA, while the heading prop will contain the main heading. The button prop will contain an object with two properties: text and url, which will be used to render a button with a link. The image prop will contain an object with properties such as url, altText, width, and height to render an image.
We can now import these components into a page template and render them on the homepage, individual artist pages, or wherever needed! For example, in the app/artist/[slug]/page.jsx file, we can modify the code to include the updated query fetching promotional blocks content.
Once we have retrieved our promotional blocks, we can use an if statement to check the type of each block and render either the Callout or CallToAction component accordingly.
Now that everything is in its right place, we can render all of our content, components, and remote source data on the artist page:
Our reusable promotional components allow us to incorporate business goals and create a scalable codebase that can be easily modified when new features are needed. Connecting a remote source allowed us to use artist metadata that will automatically update if there are any changes in the LastFM API. Moreover, by using remote source data, we avoid duplicating content that is maintained in another system. This helps us to reduce development time, increase flexibility, and maintain consistency across the content as well as our application.
For part 3 of this series, we will take our Hygraph FM project a step further and explore pagination to maintain user experience as our platform grows. In the meantime, try adding new callouts, CTAs, or new artists and see how the pages change.
Blog Author
Lo Etheridge
Senior Developer Relations
Lo is Hygraph's Senior Developer Relations Specialist. They focus on developer education around Headless CMS, JS-based frontends, and API technologies as well as the dynamic cross-functional relationship between developers and content professionals.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.