What are the prerequisites for building a car dealership website with Hygraph?
To build a car dealership website with Hygraph, you need a basic understanding of Next.js and Node.js, Node.js and NPM installed on your machine, a Hygraph account, and an Auto.dev account to fetch car details. Note: Familiarity with React and CSS is also helpful for customizing the frontend.
How do I create a Hygraph account and start a new project?
Visit the Hygraph website and click 'Get Started.' After registering, you can add a new project from scratch or choose a template. Fill out the project details, such as name, description, and data storage region, then proceed to set up your schema, content, assets, and API Playground. Note: For more complex implementations, refer to Hygraph's structured onboarding and documentation.
How long does it take to implement Hygraph for a new project?
The implementation time depends on project complexity. For simple use cases, you can get started in minutes using pre-configured starter projects or by cloning demo projects. More complex implementations benefit from Hygraph's structured onboarding, introduction calls, and comprehensive documentation. Note: Detailed limitations not publicly documented; ask sales for specifics if you have highly custom requirements. Learn more.
Features & Capabilities
What features does Hygraph offer for building content-rich applications?
Hygraph provides a GraphQL-native architecture, a low-code schema builder, content federation for integrating remote sources, user-friendly content and asset management, and an API Playground for testing queries. It supports custom schemas, granular permissions, and multi-tenancy. Note: Teams needing highly specialized workflow automation may require additional configuration or third-party tools.
How does Hygraph integrate with external data sources like Auto.dev?
Hygraph's Content Federation feature allows you to add remote sources, such as Auto.dev, directly into your schema. You can configure REST endpoints, pass input arguments (e.g., VIN), and retrieve external data via the Hygraph GraphQL endpoint. This enables seamless integration of third-party automotive data into your application. Note: Only GET requests are supported for REST remote sources in this context.
Does Hygraph support GraphQL APIs for content delivery?
Yes, Hygraph is GraphQL-native and provides robust GraphQL APIs for querying and mutating content. This allows for precise data fetching and efficient integration with modern frontend frameworks like Next.js. Note: Teams unfamiliar with GraphQL may require additional onboarding or training. API Reference.
What integrations are available with Hygraph?
Hygraph integrates with platforms such as Cloudinary, Bynder, Filestack, Scaleflex Filerobot (for DAM), EasyTranslate (localization), Netlify and Vercel (hosting), Mux (video), AWS S3 (object storage), Imgix (image optimization), Akeneo (PIM), Adminix, and Plasmic. For a full list, see the Hygraph Integrations Page. Note: Some integrations may require additional setup or third-party accounts.
Use Cases & Industry Applications
What are common use cases for Hygraph?
Hygraph is used for building content-rich applications such as car dealership websites, eCommerce platforms, media and publication sites, education technology solutions, and more. Its content federation and schema modeling features make it suitable for integrating multiple data sources and managing complex content structures. Note: For highly specialized verticals, custom development may be required.
Which industries are represented in Hygraph's case studies?
Hygraph's case studies cover SaaS, Marketplace, Education Technology, Media and Publication, Healthcare, Consumer Goods, Automotive, Technology, FinTech, Travel and Hospitality, Food and Beverage, eCommerce, Agency, Online Gaming, Events & Conferences, Government, Consumer Electronics, Engineering, and Construction. See all case studies. Note: Not all features may be relevant for every industry; review case studies for specifics.
Can you share specific customer success stories using Hygraph?
Yes. Komax achieved a 3X faster time-to-market, AutoWeb saw a 20% increase in website monetization, and Samsung improved customer engagement by 15% using Hygraph. Other examples include Dr. Oetker (global consistency and scalability), HolidayCheck (modular content model), and Fitfox (mobile-first product). Read more case studies. Note: Results may vary based on implementation and use case.
Pain Points & Problems Solved
What problems does Hygraph solve for content teams and developers?
Hygraph addresses developer dependency for content updates, legacy tech stack limitations, content inconsistency across regions, and workflow inefficiencies. It also reduces operational costs, accelerates speed-to-market, and simplifies schema evolution and integration with modern frontends. Note: Teams with highly unique workflow needs may require additional customization.
What are the main pain points Hygraph helps address for car dealership websites?
For car dealership websites, Hygraph streamlines the integration of vehicle data from sources like Auto.dev, enables easy schema customization for car details, and supports filtering and displaying inventory by price or condition. It reduces manual data entry and allows non-technical users to manage content. Note: Real-time inventory sync may require additional integration work.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (achieved August 3, 2022), ISO 27001 certified, and GDPR compliant. It offers granular permissions, audit logs, automatic backups, and encryption at rest and in transit. Note: For industry-specific compliance needs, consult Hygraph's documentation or sales team. More details.
Performance & Scalability
What are Hygraph's performance and scalability highlights?
Hygraph provides a high-performance CDN, typical API latency of 70–100ms, Smart Edge Cache for optimized content delivery, and aims for 99.9%+ availability uptime. It supports region-based hosting and is designed to scale with high traffic and large content volumes. Note: Actual performance may vary based on implementation and geographic distribution.
Support & Documentation
What technical documentation and resources are available for Hygraph users?
Hygraph offers comprehensive documentation, including Getting Started guides, API references, Assets API, GraphQL Mutations, Content Modeling, Migration Guides, Management SDK, and pre-configured starter projects. Community support is available via Slack. See documentation. Note: Some advanced topics may require direct support or consultation.
Customer Proof & Feedback
Who are some notable customers using Hygraph?
Notable customers include 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. These companies use Hygraph for content management and digital experience delivery. Note: Customer use cases vary; see case studies for details.
What feedback have customers given about Hygraph's ease of use?
Customers have highlighted Hygraph's intuitive interface and quick support. For example, Anastasija S. (Product Content Coordinator) noted, "Ease of use is another aspect I like – every change I make to Hygraph I can instantly see on the front-end." Charissa K. described it as "fast to comprehend and localizable," and Tom K. praised its support for complex websites. Note: Some advanced features may require technical expertise.
With a modern content platform like Hygraph, it’s a simple matter to tackle all of the above. Essentially a GraphQL content platform, Hygraph allows you to easily create custom schemas with its low-code schema builder and then access its stored data via the GraphQL API.
Let’s take Hygraph for a test run for the next few minutes, and see what it takes to build a car dealership website using Hygraph as a backend. This tutorial demonstrates how schemas are made and how easy it is to fetch data from a third-party API source with Hygraph. We’ll build the application frontend using Next.js.
Let’s start by obtaining the Auto.dev API keys and endpoint. Auto.dev is an automotive API provider that facilitates accessing vehicle data, such as the VIN, or listing all vehicles filtered according to your parameters. It’s simple to use and free.
Navigate to Auto.dev and create a new account by clicking Get your free API key. After creating an account, you can obtain the API endpoint and the API key from the dashboard.
Keep this tab open or save the keys somewhere—you’ll need them later.
Creating a Hygraph account
Visit the Hygraph website and click Get Started. After successfully signing up on the registration page, you can either add a project or choose a template.
For this tutorial, add a new project from scratch. Click Add Project and fill out the form with the necessary details, like the name of your project, a description, and the data storage region.
When your details are to your satisfaction, click Add Project to view a menu like this:
Schema. Allows you to create custom schemas from the intuitive GUI of Hygraph.
Content. Lets you add content to these schemas.
Assets. Lets you manage static assets like images.
API Playground. Enables you to explore the GraphQL API of your project from the dashboard.
Schemas are the heart of Hygraph. They let you create content models, add remote sources, and create enumerators depending on your preferences. So let’s create a few.
Creating schemas in Hygraph
Click Schema in the menu. You can create any type of schema you want, but for this tutorial, let’s create a model for blog posts.
Click Add next to the Models option. In the modal that opens, enter a few details about the model, like its name, the API ID you'll use to call the model, the plural form of the model, and its description.
After successfully creating the model, add the fields that this particular model offers: title, summary, and the post itself.
If you click Content from the menu at this point, you should see an option to add a new blog post.
Now that you know how to create a basic schema, let’s add a remote source for fetching vehicle details.
Adding Remote Sources to Hygraph and creating a vehicle schema
Hygraph provides a feature called Content Federation, which integrates external data sources into your Hygraph account. This enables you to easily access all your data from a single GraphQL endpoint.
This tutorial integrates the Auto.dev data source in order to access the vehicle data from the Hygraph endpoint itself. In other words, when an admin inputs a VIN of a particular vehicle into the Hygraph CMS, all the data available in Auto.dev for that vehicle can be retrieved from the GraphQL endpoint.
To achieve this, let’s add a remote source. Click Schema > Components > Add from the menu, and a new form opens up. Fill in the basic details like the name and description of the remote source, and then choose the type of source. This tutorial selects REST.
Add the base URL of the Auto.dev endpoint, which in this case is https://auto.dev/api/vin/. Add the Authorization header to authorize your requests, and add the Authorization key and the value of Bearer API_KEY so that it looks like this:
Replace API_KEY with the key that you received from the Auto.dev dashboard. You can also define custom type definitions for the API data, but let’s skip adding it for this tutorial. Click Add, and your remote source is ready.
You can now create a model to use the remote source. Click Add next to the Models option, and name it Car Detail. This model holds the car's name, a gallery for images, a description, price, and condition, along with the car details received from the API.
Add a single-line field called VIN to pass to the remote source to decode the car detail, select the REST option from the model’s sidebar, and name it something appropriate, like car info for example.
Follow this pattern to fill out the rest of the form:
Remote source. This option lets you choose which remote source you’re referencing here in case you have multiple sources. The Auto.dev API is accessible through GET request only, so there’s no need to change the default.
Input arguments. This field allows you to pass input arguments in the API call.
Path. This option allows you to append path data to the base URL. In this case, you need to append the VIN to the base URL. Using {{doc.vin}} sets the VIN of the document as a path variable. The doc object allows you to reference any field from the model. Because the API ID of VIN is vin, it’s referenced as doc.vin.
The complete model is shown below.
Adding content to Hygraph
With your model for adding car details ready, let’s add some content from the Hygraph content menu.
Click Content > Car Detail from the content menu, and then Add Entry. Let’s say you want to add a Porsche 911. The VIN of this particular model is WP0AB2A93KS114315. Fill in the form and click Save, then Publish to publish your content.
Editor's Note
You can also add a few dummy blog posts to display in the frontend via Hygraph’s Blog Posts schema.
Setting Hygraph permissions
Once you’ve added as many vehicles as you like, let’s set up Hygraph permissions to access the data in your application.
Hygraph provides you with the required endpoints, but by default, you can’t access them without setting proper permissions. To make the endpoints accessible, click Project Settings > Access > API Access. The content API endpoint is the endpoint for accessing the data in this case. You’ll need this string later.
To create a permanent auth token to use for accessing the data, scroll down the API Access page and click Add Token under under the Permanent Auth Token.
Give the token a name and a description, set the stage as Published, and click Add & configure permissions. On the permissions page, copy the bearer token. This tutorial leaves the values in the Content API section set to their default.
Your Hygraph setup is complete, but keep a note of the content endpoint and the bearer token. You’ll need them to connect the frontend.
Creating a new Next.js project is simple. Type the following command in the terminal:
npx create-next-app@latest APP_NAME
Replace APP_NAME with the name of your application. To keep this article simple, choose options similar to the image below when configuring the template.
Editor's Note
Note that this tutorial doesn’t use TypeScript or any other styling library like Tailwind.
Create a components folder in the root directory and add a new file called CarCard.jsx for displaying the car details on the homepage. Paste the following code in this component:
This component takes a few props for displaying the image, description, name, price, condition and the make of the car.
Create a new file called Car.module.css inside the styles folder and paste the following code inside it:
.container{
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 20px;
}
.image{
width: 200px;
height: 150px;
margin-right: 20px;
object-fit: cover;
border-radius: 5px;
}
.description{
display: flex;
flex-direction: column;
}
.name{
font-size: 1.5rem;
font-weight: bold;
margin: 0;
}
.make{
font-size: 1rem;
color: gray;
margin: 5px 0;
}
.details{
font-size: 1rem;
margin: 0;
}
.price{
font-size: 1rem;
color: gray;
}
.condition{
font-size: 1rem;
color: gray;
}
.button{
width: 7rem;
}
And your car card is ready. To display the details of the car on a separate page, create a new file called [id].jsx inside the pages folder. This page will work as a dynamic route.
The component is wrapped using the ApolloProvider, and the client is passed as a prop. You can access the custom hooks defined at @apollo/client from anywhere in the app now.
Let’s write a GraphQL query to get all the car details. Open the index.js file and import the following:
import{ useEffect, useState }from'react';
import{ gql, useQuery }from'@apollo/client';
importCarCardfrom'@/components/CarCard';
The useQuery hook allows you to run the queries written using gql. The useQuery hook returns three values: loading, error, and data. Until the data or an error is received, the loading value stays true. The error throws an error if there’s any, otherwise, it’s undefined, and the data holds all the data received from the endpoint.
Replace the content of Home component with the following:
exportdefaultfunctionHome(){
const[price, setPrice]=useState('all');
const{ loading, error, data }=useQuery(gql`
query MyQuery {
carDetails(where: {
${price ==='moreThan4'?'price_gt: 400000':''}
${price ==='lessThan4'?'price_lt: 400000':''}
${price ==='all'?'price_gt: 0':''}
}) {
id
description
gallery {
url
}
nameOfTheCar
price
condition
}
}
`);
const options =[
{value:'all',label:'All'},
{value:'moreThan4',label:'> 400000'},
{value:'lessThan4',label:'< 400000'},
];
constonChange=(e)=>{
setPrice(e.target.value);
console.log(e.target.value);
};
return(
<>
<Head>
<title>Create Next App</title>
<metaname='description'content='Generated by create next app'/>
The logic is straightforward here. The page has a simple select field to filter the cars. There are three view options inside the folder:
All cars
Cars that have a price lower than $400,000
Cars with a price higher than $400,000
Depending on the data, the CarCard component is rendered in a loop. For each car, the details are passed as a prop to it. A React state is defined to store the price of the chosen select value to filter cars. By default, the select field will have all as the value.
Run a query using the useQuery hook and gql.
query MyQuery{
carDetails(where:{
${price ==='moreThan4'?'price_gt: 400000':''}
${price ==='lessThan4'?'price_lt: 400000':''}
${price ==='all'?'price_gt: 0':''}
}){
id
description
gallery {
url
}
nameOfTheCar
price
condition
}
}
`);
The MyQuery has a where condition. Depending on the chosen select value, it shows cars that cost more or less than $400,000. If the select field value is all, it shows cars that cost more than $0. This query returns the ID, description, gallery image URLs, name, price, and condition of the car.
The options for the select field are hard-coded for now. The onChange function that sets the price state is defined.
Inside the return statement, the options are mapped to display them inside the select field. If loading is true, it shows a loading message, otherwise, it maps the data received from the API and passes it inside the prop of the CarCard component.
The homepage is ready, so let’s move on to the car details page, where you’ll use the data received from the remote source.
Depending on the ID of the route, let’s fetch the data from the API. Write a new GraphQL query and extract the values from there. Paste this code above the return statement:
const query = gql`
query carDetail_carInfo($id: ID!) {
values: carDetail(where: { id: $id }) {
nameOfTheCar
description
gallery {
url
}
carInfo
}
}
`;
const{ loading, error, data }=useQuery(query,{variables:{ id }});
const{ values }= loading ?{values:{}}: data;
This is similar to the query used for the homepage. The main difference is that the variable is the id of the Hygraph content ID here, and another value called carInfo is fetched from the endpoint. This carInfo endpoint returns the data received from the remote source.
If you take a look at the code for this page, you can see that the car make, model, engine, number of doors, and a few other data are fetched directly from the remote source using the Hygraph GraphQL endpoint.
Your application is now ready to test. Run the code with the npm run dev command from your terminal. This starts the Next.js server on http://localhost:3000. The following GIF demonstrates the application in action.
Your car dealership website is ready for the world!
Hygraph is a headless CMS that allows you to create highly customizable and powerful applications without worrying about the backend stack. You got to explore this functionality just now building a custom website with Hygraph and Next.js specifically for a hypothetical car dealership. This tutorial used the Auto.dev API as a remote data source to fetch information about car models via their VINs; the remote source response was directly accessible through Hygraph’s GraphQL endpoint.
Subha Chanda is a freelance web developer who's passionate about learning and experimenting with new things. He loves to write about what he's found out.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.
With a modern content platform like Hygraph, it’s a simple matter to tackle all of the above. Essentially a GraphQL content platform, Hygraph allows you to easily create custom schemas with its low-code schema builder and then access its stored data via the GraphQL API.
Let’s take Hygraph for a test run for the next few minutes, and see what it takes to build a car dealership website using Hygraph as a backend. This tutorial demonstrates how schemas are made and how easy it is to fetch data from a third-party API source with Hygraph. We’ll build the application frontend using Next.js.
Let’s start by obtaining the Auto.dev API keys and endpoint. Auto.dev is an automotive API provider that facilitates accessing vehicle data, such as the VIN, or listing all vehicles filtered according to your parameters. It’s simple to use and free.
Navigate to Auto.dev and create a new account by clicking Get your free API key. After creating an account, you can obtain the API endpoint and the API key from the dashboard.
Keep this tab open or save the keys somewhere—you’ll need them later.
Creating a Hygraph account
Visit the Hygraph website and click Get Started. After successfully signing up on the registration page, you can either add a project or choose a template.
For this tutorial, add a new project from scratch. Click Add Project and fill out the form with the necessary details, like the name of your project, a description, and the data storage region.
When your details are to your satisfaction, click Add Project to view a menu like this:
Schema. Allows you to create custom schemas from the intuitive GUI of Hygraph.
Content. Lets you add content to these schemas.
Assets. Lets you manage static assets like images.
API Playground. Enables you to explore the GraphQL API of your project from the dashboard.
Schemas are the heart of Hygraph. They let you create content models, add remote sources, and create enumerators depending on your preferences. So let’s create a few.
Creating schemas in Hygraph
Click Schema in the menu. You can create any type of schema you want, but for this tutorial, let’s create a model for blog posts.
Click Add next to the Models option. In the modal that opens, enter a few details about the model, like its name, the API ID you'll use to call the model, the plural form of the model, and its description.
After successfully creating the model, add the fields that this particular model offers: title, summary, and the post itself.
If you click Content from the menu at this point, you should see an option to add a new blog post.
Now that you know how to create a basic schema, let’s add a remote source for fetching vehicle details.
Adding Remote Sources to Hygraph and creating a vehicle schema
Hygraph provides a feature called Content Federation, which integrates external data sources into your Hygraph account. This enables you to easily access all your data from a single GraphQL endpoint.
This tutorial integrates the Auto.dev data source in order to access the vehicle data from the Hygraph endpoint itself. In other words, when an admin inputs a VIN of a particular vehicle into the Hygraph CMS, all the data available in Auto.dev for that vehicle can be retrieved from the GraphQL endpoint.
To achieve this, let’s add a remote source. Click Schema > Components > Add from the menu, and a new form opens up. Fill in the basic details like the name and description of the remote source, and then choose the type of source. This tutorial selects REST.
Add the base URL of the Auto.dev endpoint, which in this case is https://auto.dev/api/vin/. Add the Authorization header to authorize your requests, and add the Authorization key and the value of Bearer API_KEY so that it looks like this:
Replace API_KEY with the key that you received from the Auto.dev dashboard. You can also define custom type definitions for the API data, but let’s skip adding it for this tutorial. Click Add, and your remote source is ready.
You can now create a model to use the remote source. Click Add next to the Models option, and name it Car Detail. This model holds the car's name, a gallery for images, a description, price, and condition, along with the car details received from the API.
Add a single-line field called VIN to pass to the remote source to decode the car detail, select the REST option from the model’s sidebar, and name it something appropriate, like car info for example.
Follow this pattern to fill out the rest of the form:
Remote source. This option lets you choose which remote source you’re referencing here in case you have multiple sources. The Auto.dev API is accessible through GET request only, so there’s no need to change the default.
Input arguments. This field allows you to pass input arguments in the API call.
Path. This option allows you to append path data to the base URL. In this case, you need to append the VIN to the base URL. Using {{doc.vin}} sets the VIN of the document as a path variable. The doc object allows you to reference any field from the model. Because the API ID of VIN is vin, it’s referenced as doc.vin.
The complete model is shown below.
Adding content to Hygraph
With your model for adding car details ready, let’s add some content from the Hygraph content menu.
Click Content > Car Detail from the content menu, and then Add Entry. Let’s say you want to add a Porsche 911. The VIN of this particular model is WP0AB2A93KS114315. Fill in the form and click Save, then Publish to publish your content.
Editor's Note
You can also add a few dummy blog posts to display in the frontend via Hygraph’s Blog Posts schema.
Setting Hygraph permissions
Once you’ve added as many vehicles as you like, let’s set up Hygraph permissions to access the data in your application.
Hygraph provides you with the required endpoints, but by default, you can’t access them without setting proper permissions. To make the endpoints accessible, click Project Settings > Access > API Access. The content API endpoint is the endpoint for accessing the data in this case. You’ll need this string later.
To create a permanent auth token to use for accessing the data, scroll down the API Access page and click Add Token under under the Permanent Auth Token.
Give the token a name and a description, set the stage as Published, and click Add & configure permissions. On the permissions page, copy the bearer token. This tutorial leaves the values in the Content API section set to their default.
Your Hygraph setup is complete, but keep a note of the content endpoint and the bearer token. You’ll need them to connect the frontend.
Creating a new Next.js project is simple. Type the following command in the terminal:
npx create-next-app@latest APP_NAME
Replace APP_NAME with the name of your application. To keep this article simple, choose options similar to the image below when configuring the template.
Editor's Note
Note that this tutorial doesn’t use TypeScript or any other styling library like Tailwind.
Create a components folder in the root directory and add a new file called CarCard.jsx for displaying the car details on the homepage. Paste the following code in this component:
This component takes a few props for displaying the image, description, name, price, condition and the make of the car.
Create a new file called Car.module.css inside the styles folder and paste the following code inside it:
.container{
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 20px;
}
.image{
width: 200px;
height: 150px;
margin-right: 20px;
object-fit: cover;
border-radius: 5px;
}
.description{
display: flex;
flex-direction: column;
}
.name{
font-size: 1.5rem;
font-weight: bold;
margin: 0;
}
.make{
font-size: 1rem;
color: gray;
margin: 5px 0;
}
.details{
font-size: 1rem;
margin: 0;
}
.price{
font-size: 1rem;
color: gray;
}
.condition{
font-size: 1rem;
color: gray;
}
.button{
width: 7rem;
}
And your car card is ready. To display the details of the car on a separate page, create a new file called [id].jsx inside the pages folder. This page will work as a dynamic route.
The component is wrapped using the ApolloProvider, and the client is passed as a prop. You can access the custom hooks defined at @apollo/client from anywhere in the app now.
Let’s write a GraphQL query to get all the car details. Open the index.js file and import the following:
import{ useEffect, useState }from'react';
import{ gql, useQuery }from'@apollo/client';
importCarCardfrom'@/components/CarCard';
The useQuery hook allows you to run the queries written using gql. The useQuery hook returns three values: loading, error, and data. Until the data or an error is received, the loading value stays true. The error throws an error if there’s any, otherwise, it’s undefined, and the data holds all the data received from the endpoint.
Replace the content of Home component with the following:
exportdefaultfunctionHome(){
const[price, setPrice]=useState('all');
const{ loading, error, data }=useQuery(gql`
query MyQuery {
carDetails(where: {
${price ==='moreThan4'?'price_gt: 400000':''}
${price ==='lessThan4'?'price_lt: 400000':''}
${price ==='all'?'price_gt: 0':''}
}) {
id
description
gallery {
url
}
nameOfTheCar
price
condition
}
}
`);
const options =[
{value:'all',label:'All'},
{value:'moreThan4',label:'> 400000'},
{value:'lessThan4',label:'< 400000'},
];
constonChange=(e)=>{
setPrice(e.target.value);
console.log(e.target.value);
};
return(
<>
<Head>
<title>Create Next App</title>
<metaname='description'content='Generated by create next app'/>
The logic is straightforward here. The page has a simple select field to filter the cars. There are three view options inside the folder:
All cars
Cars that have a price lower than $400,000
Cars with a price higher than $400,000
Depending on the data, the CarCard component is rendered in a loop. For each car, the details are passed as a prop to it. A React state is defined to store the price of the chosen select value to filter cars. By default, the select field will have all as the value.
Run a query using the useQuery hook and gql.
query MyQuery{
carDetails(where:{
${price ==='moreThan4'?'price_gt: 400000':''}
${price ==='lessThan4'?'price_lt: 400000':''}
${price ==='all'?'price_gt: 0':''}
}){
id
description
gallery {
url
}
nameOfTheCar
price
condition
}
}
`);
The MyQuery has a where condition. Depending on the chosen select value, it shows cars that cost more or less than $400,000. If the select field value is all, it shows cars that cost more than $0. This query returns the ID, description, gallery image URLs, name, price, and condition of the car.
The options for the select field are hard-coded for now. The onChange function that sets the price state is defined.
Inside the return statement, the options are mapped to display them inside the select field. If loading is true, it shows a loading message, otherwise, it maps the data received from the API and passes it inside the prop of the CarCard component.
The homepage is ready, so let’s move on to the car details page, where you’ll use the data received from the remote source.
Depending on the ID of the route, let’s fetch the data from the API. Write a new GraphQL query and extract the values from there. Paste this code above the return statement:
const query = gql`
query carDetail_carInfo($id: ID!) {
values: carDetail(where: { id: $id }) {
nameOfTheCar
description
gallery {
url
}
carInfo
}
}
`;
const{ loading, error, data }=useQuery(query,{variables:{ id }});
const{ values }= loading ?{values:{}}: data;
This is similar to the query used for the homepage. The main difference is that the variable is the id of the Hygraph content ID here, and another value called carInfo is fetched from the endpoint. This carInfo endpoint returns the data received from the remote source.
If you take a look at the code for this page, you can see that the car make, model, engine, number of doors, and a few other data are fetched directly from the remote source using the Hygraph GraphQL endpoint.
Your application is now ready to test. Run the code with the npm run dev command from your terminal. This starts the Next.js server on http://localhost:3000. The following GIF demonstrates the application in action.
Your car dealership website is ready for the world!
Hygraph is a headless CMS that allows you to create highly customizable and powerful applications without worrying about the backend stack. You got to explore this functionality just now building a custom website with Hygraph and Next.js specifically for a hypothetical car dealership. This tutorial used the Auto.dev API as a remote data source to fetch information about car models via their VINs; the remote source response was directly accessible through Hygraph’s GraphQL endpoint.
Subha Chanda is a freelance web developer who's passionate about learning and experimenting with new things. He loves to write about what he's found out.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.