What is a component in Hygraph and how is it used?
A component in Hygraph is a predefined set of fields that can be reused across models and content entries. It acts as a flexible, reusable template: you define the fields once, and then fill them with different content each time you use it in a content entry. Components help declutter your content creation screen and save time by allowing you to reuse field structures. Note: Components do not currently support remote sources or embedding for the Rich Text editor. For more details, see the official documentation.
What are the differences between basic and modular component fields in Hygraph?
Basic component fields allow only one component type to be attached, and you can limit the number of component instances to one or allow multiple. Modular component fields can have two or more component types attached, and both types can be configured to allow multiple values, enabling multiple component instances in a content entry. Note: The number of components you can create depends on your project's plan. See the pricing page for details.
How do you create and add a component to your model in Hygraph?
To create a component, navigate to the Schema Builder, find the Components section, and click '+Add'. Enter the display name, and the API ID fields will be auto-filled. After creating the component, add fields as needed. To add the component to your model, select either a basic or modular component field in your model, configure its properties, and select the component(s) to attach. For step-by-step instructions, refer to the documentation. Note: The number of components is limited by your plan, and only the first 50 component instances are visible in the UI; additional instances are queryable via the API.
What are nested components in Hygraph and how do you use them?
Nested components allow you to add component fields to a component, enabling a parent component to contain one or more child components. This is useful for creating hierarchical structures, such as a section with subsections. To use nested components, create the necessary components, add a basic or modular component field to the parent, and select the child component(s) to nest. The maximum nesting level is 4. For more, see the nested components documentation. Note: Exceeding 4 levels of nesting is not supported.
How do you query components in Hygraph using the API?
Once a component field is configured, it is immediately queryable through the API. Basic component fields are queried like regular fields inside your models. Modular component fields are union types, so you use GraphQL fragments (e.g., ... on ComponentType) to query each type. For example queries and results, see the querying components documentation. Note: Only the first 50 component instances are visible in the UI, but all are accessible via the API.
What are the limitations of components in Hygraph?
Current limitations include: components do not support remote sources or embedding for the Rich Text editor; only the first 50 component instances are visible in the UI (additional instances are queryable via the API); and the maximum nesting level for components is 4. The number of components you can create is determined by your plan. For the latest details, see the pricing page. Note: These limitations may affect complex content modeling scenarios.
How do components differ from references (relations) in Hygraph?
Components reuse only the set of fields (structure) without any content, while references (relations) reuse existing content entries. Use references when you want to attach existing entries (e.g., a fixed set of authors), and components when you want to define new content each time (e.g., many different users as authors without creating profiles for each). For more, see the documentation. Note: Choosing the wrong approach can lead to inefficient content management.
Technical Documentation & Support
Where can I find technical documentation for working with components in Hygraph?
Comprehensive technical documentation is available at Hygraph Classic Docs: Components. For broader topics, including API reference, content modeling, and advanced features, visit the Hygraph Documentation. Note: Documentation is updated regularly; check for the latest guidance.
How many component instances can I add to a component field in Hygraph?
There is currently no hard limit to the number of component instances you can add to a component field, but only the first 50 are visible in the UI. All instances are fully queryable through the API. Note: Managing large numbers of component instances may require API-based workflows for full visibility.
Pricing & Plan Considerations
Does the number of components I can create depend on my Hygraph plan?
Yes, the number of components you can create is based on your project's current plan. For up-to-date details on limits and features by plan, visit the Hygraph pricing page. Note: Plan limits may affect complex schema designs; review before scaling your project.
A component is a predefined set of fields that can be reused across models and content entries. You can think of a component as a flexible, reusable template where you define the fields that will be used inside a component once, and then fill them with different content every time you use it in a content entry.
Component: a predefined set of fields that can be reused across models and content entries. You can think of a component as a flexible, reusable template: you define the fields that will be used inside a component once, and then fill them with different content every time you use it in a content entry.
Component instance: a specific occurrence of the component type, containing content, inside a content entry. While there is no limit to the number of component instances that you can add to a component field yet, you will only be able to see the first 50 in the UI.
Component field: a special field type in your Hygraph schema that defines which components of which type can be used in a model. Component fields can be of basic or modular types.
Basic component field: a basic component field can only have one component attached to it. You can limit the number of component instances to one, or allow multiple component instances to be added in the content entry.
Modular component field: a modular component field can have two or more components attached to it.
Both Basic and Modular component fields can be configured to allow multiple values. If multiple values are allowed for a component field, this field will allow for multiple component instances to be added to a content entry.
Nested components: functionality that allows you to create components within a component, as if you had a parent component containing one or more child components.
In the left sidebar, find the Components section below your Models and click on +Add.
Add the name of your component in the Display name field, the API ID and Plural API ID will be auto-filled by the system.
Click on Create component.
Add different fields to your component. For example, we can create an Address component for our Organization model. For that, we will add single-line text fields for the Address lines and City, as well as a number field for ZIP code.
Creating a component
Keep in mind the number of components is based on your project's current plan. Click here to find out more about our pricing.
While there is no limit to the number of component instances that you can add to a component field yet, you will only be able to see the first 50 in the UI. Beyond those first 50, they are fully queryable through the API Playground, but you won't be able to see them in the UI.
Navigate to the Schema builder, and then to the model you wish to add your component to.
Select a Basic component field or a Modular component field from the Add fields right sidebar. You can learn about the differences between them here.
Add the name of your component field in the Display name field, the API ID will be auto-filled by the system. Optionally, you can also add a Description. This screen allows you to control different properties of your component field: you can allow multiple component instances to be added by allowing multiple values, or you can make this field required in the Advanced section.
Use the dropdown at the bottom of the screen to pick the component - or several components - that you wish to have in your component field. This dropdown will be named Select component if you're creating a basic component field, or Select allowed components if you're creating a modular component field.
After adding a component to your model, navigate to the content editing section to test your new or updated model.
Click on the + Create item button.
You will be able to see your component field in the content entry.
If it's a basic component field, click the +Add component button, if it's a modular component field, select a component from the drop-down menu.
Add a new component to an entry
You've just created your first component instance! Now it's time to add some content to this instance.
Add content on a component
If you previously selected Allow multiple values on your component field's parameters, you will be able to add a different component instance by using the +Add another component button at the bottom of your component field, or by using the ••• sub-menu and selecting Add component below or Add component above.
Add multiple component instances
You can also remove and reorder your component instances using the ••• sub-menu or the arrows next to it.
The nested components functionality enhances how you can reuse and edit your models by allowing you to add component fields to a component.
Using nested components you can have a parent component where one or more child components are nested. This would allow you to, for instance, create a section and a subsection component, and then embed one into the other.
Add either a basic or modular component field to the component you wish to add the nested component to. You will find them on the Add fields right sidebar.
Keep in mind that, when you add a component field, the options offered when selecting the nested components are other components already created. So make sure you have created the components you need before doing this.
Select the component you wish to nest into the current one from the Select components dropdown at the bottom of the screen if it's a basic component field, or the Select allowed components dropdown if it's a modular component field.
Select nested components
Click on the Create button.
As a result, your new nested component field is now displayed on the fields list of the parent component.
Finally, you can go to the Content editing section and create a new entry, where you will have the option of adding the newly created nested component as a subsection of the component you added it to.
Add nested components
Keep in mind that the maximum level of nesting is 4.
After a component field has been configured, it's added to the Hygraph schema and becomes immediately queryable through the API. Press CTRL+Space or open the Explorer view to see the available fields inside the model that contains a component field.
Basic component fields are queried in the same way, as you would query regular fields inside your models. In the example below, a user has a page model with a basic hero component field that has cta, description and heroImage fields. Here's an example of a query with this setup:
querybasicComponent{
pages{
id
title
mainText
hero{
#note that in the case of basic components, we're only using the component field's API ID, and we don't need to use the API ID of the component itself
cta
decription
heroImage{
url
height
width
}
}
}
}
The query above will return a result like this:
{
"data":{
"pages":[
{
"id":"cl120a7gvu57b0bt3qw4xiv86",
"title":"Open positions at Hygraph",
"mainText":"Follow this link to see all of the open positions - https://jobs.hygraph.com/",
"hero":[
{
"cta":"Explore vacancies!",
"description":"There are a huge variety of positions to be filled now",
Modular component fields are union types “under the hood”, so querying works the same way as with relations and unions. In the example below, a user has a blogPost model with some regular fields, such as id, title and mainText, as well as the modular additionalSections component field. The modular component field has two different components: Contributor and VideoBlock. To query the two components inside the modular component field, we're going to use ... on Contributor and ... on VideoBlock, as we would do with a regular union type:
querymodularComponent{
blogPost(where:{id:"cl11z0rctt6g80bt3anxt7c11"}){
id
title
mainText{
markdown
}
categories{
categoryName
}
additionalSections{
__typename# if you have multiple component instances, it's recommended to use __typename to know which fields belong to which component instance.
...onContributor{
id
name
jobTitle
}
...onVideoBlock{
id
title
description
youTubeEmbedUrl
autoplay
}
}
}
}
This query will return something like this:
{
"data":{
"blogPost":{
"id":"cl11z0rctt6g80bt3anxt7c11",
"title":"Berlin in spring",
"mainText":{
"markdown":"The best time to visit the German capital is the end of April\n"
},
"categories":[
{
"categoryName":"General"
}
],
"additionalSections":[
{
"__typename":"VideoBlock",
"id":"cl11z858dt6te0ftjxi5ucvwx",
"title":"Spring in Berlin",
"description":"Watch this video for some travelling inspiration",
Components are somewhat similar to references (relations) because in both cases something gets reused. The important difference is that in the case of components, only the set of fields without any content gets reused, whereas in the case of relations, already existing content entries get reused.
Let's use an example of an Author component. Authors can be attached to a content entry using either components or relations.
In the case of relations, you need to create your Authors first, in a separate model, and then reuse these content entries by attaching them to a post using the relation field. This works well if you have a small team of authors each of whom has their own Author profile.
In the case of components, you don't have to create Author entries before creating a Blog post content entry. However, every time you add an Author component instance to your post, you will need to fill in all of the fields from scratch. This works well if many different users can be the Authors of your content entries and it doesn’t make sense to create an Author profile for each of them.
A component is a predefined set of fields that can be reused across models and content entries. You can think of a component as a flexible, reusable template where you define the fields that will be used inside a component once, and then fill them with different content every time you use it in a content entry.
Component: a predefined set of fields that can be reused across models and content entries. You can think of a component as a flexible, reusable template: you define the fields that will be used inside a component once, and then fill them with different content every time you use it in a content entry.
Component instance: a specific occurrence of the component type, containing content, inside a content entry. While there is no limit to the number of component instances that you can add to a component field yet, you will only be able to see the first 50 in the UI.
Component field: a special field type in your Hygraph schema that defines which components of which type can be used in a model. Component fields can be of basic or modular types.
Basic component field: a basic component field can only have one component attached to it. You can limit the number of component instances to one, or allow multiple component instances to be added in the content entry.
Modular component field: a modular component field can have two or more components attached to it.
Both Basic and Modular component fields can be configured to allow multiple values. If multiple values are allowed for a component field, this field will allow for multiple component instances to be added to a content entry.
Nested components: functionality that allows you to create components within a component, as if you had a parent component containing one or more child components.
In the left sidebar, find the Components section below your Models and click on +Add.
Add the name of your component in the Display name field, the API ID and Plural API ID will be auto-filled by the system.
Click on Create component.
Add different fields to your component. For example, we can create an Address component for our Organization model. For that, we will add single-line text fields for the Address lines and City, as well as a number field for ZIP code.
Creating a component
Keep in mind the number of components is based on your project's current plan. Click here to find out more about our pricing.
While there is no limit to the number of component instances that you can add to a component field yet, you will only be able to see the first 50 in the UI. Beyond those first 50, they are fully queryable through the API Playground, but you won't be able to see them in the UI.
Navigate to the Schema builder, and then to the model you wish to add your component to.
Select a Basic component field or a Modular component field from the Add fields right sidebar. You can learn about the differences between them here.
Add the name of your component field in the Display name field, the API ID will be auto-filled by the system. Optionally, you can also add a Description. This screen allows you to control different properties of your component field: you can allow multiple component instances to be added by allowing multiple values, or you can make this field required in the Advanced section.
Use the dropdown at the bottom of the screen to pick the component - or several components - that you wish to have in your component field. This dropdown will be named Select component if you're creating a basic component field, or Select allowed components if you're creating a modular component field.
After adding a component to your model, navigate to the content editing section to test your new or updated model.
Click on the + Create item button.
You will be able to see your component field in the content entry.
If it's a basic component field, click the +Add component button, if it's a modular component field, select a component from the drop-down menu.
Add a new component to an entry
You've just created your first component instance! Now it's time to add some content to this instance.
Add content on a component
If you previously selected Allow multiple values on your component field's parameters, you will be able to add a different component instance by using the +Add another component button at the bottom of your component field, or by using the ••• sub-menu and selecting Add component below or Add component above.
Add multiple component instances
You can also remove and reorder your component instances using the ••• sub-menu or the arrows next to it.
The nested components functionality enhances how you can reuse and edit your models by allowing you to add component fields to a component.
Using nested components you can have a parent component where one or more child components are nested. This would allow you to, for instance, create a section and a subsection component, and then embed one into the other.
Add either a basic or modular component field to the component you wish to add the nested component to. You will find them on the Add fields right sidebar.
Keep in mind that, when you add a component field, the options offered when selecting the nested components are other components already created. So make sure you have created the components you need before doing this.
Select the component you wish to nest into the current one from the Select components dropdown at the bottom of the screen if it's a basic component field, or the Select allowed components dropdown if it's a modular component field.
Select nested components
Click on the Create button.
As a result, your new nested component field is now displayed on the fields list of the parent component.
Finally, you can go to the Content editing section and create a new entry, where you will have the option of adding the newly created nested component as a subsection of the component you added it to.
Add nested components
Keep in mind that the maximum level of nesting is 4.
After a component field has been configured, it's added to the Hygraph schema and becomes immediately queryable through the API. Press CTRL+Space or open the Explorer view to see the available fields inside the model that contains a component field.
Basic component fields are queried in the same way, as you would query regular fields inside your models. In the example below, a user has a page model with a basic hero component field that has cta, description and heroImage fields. Here's an example of a query with this setup:
querybasicComponent{
pages{
id
title
mainText
hero{
#note that in the case of basic components, we're only using the component field's API ID, and we don't need to use the API ID of the component itself
cta
decription
heroImage{
url
height
width
}
}
}
}
The query above will return a result like this:
{
"data":{
"pages":[
{
"id":"cl120a7gvu57b0bt3qw4xiv86",
"title":"Open positions at Hygraph",
"mainText":"Follow this link to see all of the open positions - https://jobs.hygraph.com/",
"hero":[
{
"cta":"Explore vacancies!",
"description":"There are a huge variety of positions to be filled now",
Modular component fields are union types “under the hood”, so querying works the same way as with relations and unions. In the example below, a user has a blogPost model with some regular fields, such as id, title and mainText, as well as the modular additionalSections component field. The modular component field has two different components: Contributor and VideoBlock. To query the two components inside the modular component field, we're going to use ... on Contributor and ... on VideoBlock, as we would do with a regular union type:
querymodularComponent{
blogPost(where:{id:"cl11z0rctt6g80bt3anxt7c11"}){
id
title
mainText{
markdown
}
categories{
categoryName
}
additionalSections{
__typename# if you have multiple component instances, it's recommended to use __typename to know which fields belong to which component instance.
...onContributor{
id
name
jobTitle
}
...onVideoBlock{
id
title
description
youTubeEmbedUrl
autoplay
}
}
}
}
This query will return something like this:
{
"data":{
"blogPost":{
"id":"cl11z0rctt6g80bt3anxt7c11",
"title":"Berlin in spring",
"mainText":{
"markdown":"The best time to visit the German capital is the end of April\n"
},
"categories":[
{
"categoryName":"General"
}
],
"additionalSections":[
{
"__typename":"VideoBlock",
"id":"cl11z858dt6te0ftjxi5ucvwx",
"title":"Spring in Berlin",
"description":"Watch this video for some travelling inspiration",
Components are somewhat similar to references (relations) because in both cases something gets reused. The important difference is that in the case of components, only the set of fields without any content gets reused, whereas in the case of relations, already existing content entries get reused.
Let's use an example of an Author component. Authors can be attached to a content entry using either components or relations.
In the case of relations, you need to create your Authors first, in a separate model, and then reuse these content entries by attaching them to a post using the relation field. This works well if you have a small team of authors each of whom has their own Author profile.
In the case of components, you don't have to create Author entries before creating a Blog post content entry. However, every time you add an Author component instance to your post, you will need to fill in all of the fields from scratch. This works well if many different users can be the Authors of your content entries and it doesn’t make sense to create an Author profile for each of them.