What is Hygraph and how does it support composable content infrastructure?
Hygraph is a headless content management system (CMS) designed to promote composability within your content infrastructure. It offers native GraphQL integration, enabling efficient data retrieval and supporting Content Federation to create unified content experiences across multiple sources. Learn more.
What is Content Federation and how does Hygraph implement it?
Content Federation is the process of aggregating data and content from multiple sources and presenting it through a unified API endpoint. Hygraph implements Content Federation by allowing you to add remote sources (such as GraphQL APIs) to your project, define models that incorporate both local and remote fields, and query all data seamlessly via a single GraphQL endpoint. Read more.
Technical Implementation & Developer Experience
How do I set up a Hygraph project for federated content?
To set up a Hygraph project for federated content, create a free-forever account on Hygraph, add a new project, and configure its name, description, and region. You can then add remote sources (such as GraphQL APIs) to your schema and define models that include both local and remote fields. See step-by-step guide.
How do I add a remote GraphQL source to Hygraph?
Navigate to Schema > Remote Sources in your Hygraph project and click the "+Add" button. Enter the display name, select "GraphQL" as the type, and provide the base URL of your remote endpoint. This allows you to query external APIs and integrate their data into your Hygraph models. Documentation | Video tutorial
How do I create and configure models in Hygraph for federated content?
In Hygraph, models serve as content blueprints. You can define fields for each model, including local fields (e.g., text, string) and remote fields (from external sources). For example, you might create a "Store" model with fields for "name", "city", and "products" (the latter being a remote field from a federated source). Learn more.
How do I connect a Svelte application to Hygraph's GraphQL API?
To connect a Svelte application to Hygraph's GraphQL API, use the graphql-request library. Obtain your Hygraph API endpoint from Project Settings > ACCESS > API Access > Endpoints, store it as an environment variable, and use GraphQLClient to make queries. This enables you to fetch federated content and display it in your Svelte app. See example code.
Does Hygraph support Svelte and other modern frameworks?
Yes, Hygraph supports Svelte and other modern frameworks such as React, Vue, and Next.js. It provides examples and documentation for integrating with SvelteKit, leveraging its performant GraphQL API and federated content capabilities. See examples.
Features & Capabilities
What are the key features of Hygraph?
Hygraph offers a GraphQL-native architecture, content federation, scalability, and a wide range of integrations (including Netlify, Vercel, Shopify, AWS S3, Cloudinary, and more). It provides an intuitive interface praised for ease of use, supports enterprise-grade security, and enables rapid content delivery for modern digital experiences. Explore features.
What integrations does Hygraph support?
Hygraph supports integrations for hosting and deployment (Netlify, Vercel), eCommerce (Shopify, BigCommerce, commercetools), localization (Lokalise, Crowdin, EasyTranslate, Smartling), digital asset management (AWS S3, Cloudinary, Bynder, Aprimo, Mux, Scaleflex Filerobot), personalization (Ninetailed), AI (AltText.ai), and more. See full list.
Does Hygraph provide an API for content management?
Yes, Hygraph provides a powerful GraphQL API for efficient content fetching and management. The API supports federated queries, enabling you to retrieve data from multiple sources via a single endpoint. API Reference.
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.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant, ISO 27001 certified, and GDPR compliant. It offers enterprise-grade security features such as 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 pricing and feature breakdowns, visit the pricing page.
Use Cases & Customer Success
Who can benefit from using Hygraph?
Hygraph is ideal for developers, IT decision-makers, content creators, project/program managers, agencies, solution partners, and technology partners. It serves modern software companies, enterprises seeking to modernize, and brands aiming to scale across geographies or re-platform from legacy solutions. See case studies.
What industries are represented in Hygraph's customer case studies?
Hygraph's case studies span industries such as food and beverage (Dr. Oetker), consumer electronics (Samsung), automotive (AutoWeb), healthcare (Vision Healthcare), travel and hospitality (HolidayCheck), media and publishing, eCommerce, SaaS (Bellhop), marketplace, education technology, and wellness and fitness. Explore case studies.
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, Samsung improved customer engagement with a scalable platform, and Dr. Oetker enhanced their digital experience using MACH architecture. See more success stories.
How long does it take to implement Hygraph and how easy is it to start?
Hygraph is designed for quick implementation and ease of use. For example, Top Villas launched a new project in just 2 months from initial contact. Non-technical users can get started quickly by signing up for a free account and using documentation and onboarding guides. Documentation.
What business impact can customers expect from using Hygraph?
Customers can expect time-saving through streamlined workflows, ease of use with an intuitive interface, faster speed-to-market, and enhanced customer experience through scalable content delivery. These benefits help modernize tech stacks and drive operational efficiency. Learn more.
Pain Points & Solutions
What problems does Hygraph solve?
Hygraph addresses operational pains (reliance on developers for content updates, outdated tech stacks, conflicting global team needs, clunky content creation), financial pains (high operational costs, slow speed-to-market, expensive maintenance, scalability challenges), and technical pains (boilerplate code, overwhelming queries, evolving schemas, cache and OpenID integration issues). See details.
How does Hygraph solve pain points for different personas?
For developers, Hygraph reduces boilerplate code and streamlines query management. For content creators and project managers, it provides an intuitive interface for independent content updates. For business stakeholders, it lowers operational costs, supports scalability, and accelerates speed-to-market. See persona solutions.
What KPIs and metrics are associated with the pain points Hygraph solves?
Key metrics include time saved on content updates, system uptime, consistency across regions, user satisfaction scores, reduction in operational costs, time to market, maintenance costs, scalability metrics, and performance during peak usage. See KPI blog.
Support & Resources
What support and training does Hygraph offer?
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. Contact support.
Where can I find technical documentation for Hygraph?
Comprehensive technical documentation is available at hygraph.com/docs, covering everything from setup to advanced integrations and API usage.
Customer Proof & Recognition
Who are some of Hygraph's customers?
Hygraph is trusted by leading brands such as Sennheiser, HolidayCheck, Ancestry, Samsung, Dr. Oetker, Epic Games, Bandai Namco, Gamescom, Leo Vegas, and Clayton Homes. See customer logos and stories.
Getting Started
How can I get started with Hygraph?
You can sign up for a free-forever account at app.hygraph.com. Resources such as documentation, video tutorials, and onboarding guides are available to help you get started quickly.
How to implement federated content in Hygraph and Svelte
We will explore a use case demonstrating content integration from Federate This using GraphQL.
Written by Motunrayo
on Apr 02, 2024
Hygraph is a headless content management system (CMS) that promotes composability within a content infrastructure. It offers native GraphQL integration that facilitates efficient data retrieval and enables Content Federation to create unified content experiences.
Svelte is a JavaScript framework known for its distinctive approach to user interface development. Svelte's focus on simplicity, performance, and developer experience has increased its popularity within the web development community.
This article will closely examine federated content management using Hygraph and Svelte. Specifically, we will explore a use case demonstrating content integration from Federate Thisusing GraphQL and discuss the optimal method for establishing a GraphQL connection to Svelte.
Content Federation refers to the process of aggregating data and content from multiple sources and presenting it to users through a unified API endpoint as if sourced from a singular origin. This approach allows seamless access to information from various sources, facilitating efficient data management.
Hygraph, a prominent Content Federation player, offers a suite of mock data APIs via Federate This. These APIs used for demo purposes can be added alongside other APIs in a Hygraph project and queried via a single API.
Let’s explore Hygraph’s Content Federation support using the "Products routes" provided on Federate This and create a Hygraph model.
The “Products routes” showcase a list of dummy products. We will add this route as a remote source on Hygraph — but to do that, you’ll need an account with Hygraph. You can get a free-forever developer account if you don't have one.
After creating an account on Hygraph, you’ll be prompted to go to create a new project.
By clicking “Add project,” we see the view below, where we add our project's name, description, and region.
After filling in the necessary fields, click "Add project" to finalize the process. This action leads us to the project statistics page, providing an overview of the newly created project.
Hygraph facilitates Content Federation through its "remote source" feature. To import data from the "Products routes" into Hygraph, create a remote source within the Hygraph project. To do so, navigate to Schema > Remote Sources and click on the "+Add" button, as illustrated below:
Clicking on the "+Add" button opens a form, where we’ll fill in the following details:
Display name: Enter "Product Source"
Type: Select "GraphQL"
Base URL: Enter the endpoint for our "Product routes" (https://federatethis.com/api/graphql/products), which we will use for queries
For a visual guide, please watch the video below:
Once these details are filled in, the view should look like the below:
To make queries or request data from a remote source, we can use different methods such as:
Remote content: This allows us to add data from external systems directly in Hygraph models, and it can be achieved via remote fields and top level remote fields.
Custom types: Uses GraphQL types that work together with Hygraph’s autogenerated types to create a unified schema for the Hygraph content and the remote data.
Custom input type: Defines input parameters using GraphQL types when making queries to a remote source.
Remote fields enable external data retrieval, and in this implementation, we will use the “remote fields” method due to its tight integration with Hygraph models, which will give us more granular control over data fetching. To do this, we will create a model and add the “products” fields as part of its fields.
In Hygraph, a model serves as a content blueprint. Within a model, we can define fields that outline the content's schema and illustrate how various content pieces are interconnected.
To create a model, navigate to Schema > Models and click on “+Add” as seen below:
This opens up the modal below, which we fill with the appropriate information. In our case, we want to add a “Store” model.
By selecting "Add Model," we create a Store model. Next, we will define fields for this model. Specifically, we’ll create three fields: "name", "city" and “products” - where “products” will be a remote field from the products “remote source” we added earlier.
To add these fields, navigate to the right sidebar under the "Add Fields" header and choose the appropriate data type for each field.
Both "name" and "city" are string fields for this model. Therefore, we will select "Single line Text" and provide the required information. Repeat this step for the "city" field.
To add the “products” field, select “GraphQL” as the type of field. In the “Remote Source” we can already see the “Product Source” selected, so we will leave it as it is. We will add the display name as “products” and select the query as “Products” query. We will not add any “input argument” as we want to get all the products.
At this point, we should have our view looking like this:
The “Store” model should also look like the below:
With the "Store" model created, we will now add content to it. To do this, navigate to Content > Default views, where you’ll find the Store model we created. To add content, click the "+Add entry" button located at the top right corner of the page, as depicted in the image below:
Clicking on the button brings up the view below, where we will input the provided information and save it.
Upon completion, the view should look like the one depicted below:
Now that we have the content set up let’s query this data from the API playground. Copy the query below into the playground.
query MyQuery{
stores {
city
name
}
}
Running this query returns the response below:
In the image above, the response displays the content of the fields defined in the "Store" model.
Now, let’s enhance the query by including a request to fetch the "Product routes" we previously imported via a Hygraph remote source. Copy the provided query into the API playground and execute it.
query MyQuery{
stores {
city
name
products {
id
image
name
price
description
}
}
}
In the image above, we can view the response tab, which shows data for both the products and the store’s content.
With this configuration in place and the response successfully displayed, let’s explore how we can query and present this data in a Svelte app.
We‘ll create a new Svelte app using the npm create svelte@latest command. This will also provide a list of options for selecting the appropriate fit for the project.
WhichSvelte app template?
Select>Skeleton project
Add type checking withTypeScript?
Select>No//You can select a different option for this
Styling a Svelte app with Tailwind CSS
The CSS framework we will use in this project is Tailwind CSS, which you’ll need to configure by following the installation steps here.
#Making GraphQL connection with a Svelte application
Connecting a GraphQL endpoint with a Svelte application happens in various ways. One such way is through the use of “graphql-request”.
graphql-request is a lightweight and intuitive API that makes integrating Svelte applications with GraphQL APIs easy without introducing unnecessary complexity. With graphql-request, we can quickly fetch data from GraphQL APIs using asynchronous programming techniques such as async/await, aligning well with Svelte's reactive programming model.
Now, let’s connect our Hygraph project with our Svelte applications and make queries.
Connecting Svelte with the Hygraph’s project GraphQL API
We will first need to obtain our access URL to establish a connection between our application and the Hygraph GraphQL endpoint. To accomplish this, we will navigate to our Hygraph project and access Project Settings > ACCESS > API Access > Public Content API to configure our API permissions as illustrated below:
Following this, proceed to Project Settings > ACCESS > API Access > Endpoints, where you’ll obtain the Content API. Copy the “high-performance content API” and incorporate it as an environmental variable in your Svelte application for future use in GraphQL requests.
To achieve this, we will create a file named .env and insert the following into it:
VITE_HYGRAPH_URL=add your url
For security reasons, handle API keys with care and avoid exposing them.
Next, we will install graphql-request into our Svelte application like so:
npm i graphql-request
Now, let‘s navigate to the routes>+page.svelte and add the code below into our <script> tag. This code fetches the product, store data from the Content API endpoint, populates the products, and stores variable.
Now, let us break down what we achieved in the code block above:
Imports: The script imports necessary modules and dependencies. These include a CSS file (app.css), the onMount function from Svelte, and the gql and GraphQLClient objects from the graphql-request library. Additionally, it imports the ProductCard component from the specified location.
Exported variables: Two variables, products and stores, were exported from the script. These variables will hold the fetched data.
onMount hook: The onMount function is a Svelte lifecycle function that runs when the component is mounted to the DOM. Inside this hook, an asynchronous function is defined to fetch data from the GraphQL API.
GraphQL client initialization: Within the asynchronous function, the script obtains the GraphQL API endpoint URL from the .env file using import.meta.env.VITE_HYGRAPH_URL. It then initializes a new GraphQL client (client) using this URL.
GraphQL query: The script constructs a GraphQL query using the gql template literal. The query requests data for products and stores, specifying the fields to retrieve for each.
Data fetching: The script requests the GraphQL API using the initialized client (client.request(query)). Upon receiving a response, the data for products and stores is extracted from the response.
Data assignment: The fetched data is assigned to the products and stores variables. This updates the variables with the retrieved data, making it available for use in the Svelte component.
Error handling: If an error occurs during the data fetching process, it is caught and logged to the console using console.error.
Creating a card component
Next we’ll create a reusable Svelte component that displays the product details from the GraphQL request. To do that, we will create a file in src > components named “ProductCard.svelte” and add the code below:
In the code above, we used the {#each stores as store} Svelte syntax to iterate over the "stores" array and created a table row for each store.
In the browser, we can see our Svelte application looking like this:
The complete code for the application above can be found here.
This article explored Content Federation and its significance in modern application development. We walked through setting up a Hygraph project, leveraged the power of Hygraph's Content Federation capabilities to combine data from multiple sources seamlessly, and integrated a Svelte app with GraphQL for efficient data fetching.
There’s still a lot more to try out with Hygraph. By creating a free-forever account on Hygraph and exploring more instances of Federate This, you’ll gain a better understanding and hands-on experience of the Content Federation. The Hygraph Slack community is also a great place to share any challenge you may encounter while using Hygraph or chat with the Hygraph team.
Blog Author
Motunrayo Moronfolu
Senior Frontend Engineer and Technical writer passionate about building and writing about great user experiences.
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.