Frequently Asked Questions

Getting Started with Hygraph & GraphQL Code Generator

What is the GraphQL Code Generator and how does it work with Hygraph?

The GraphQL Code Generator is an open-source tool by The Guild that generates code from your Hygraph schema. It automates the creation of type-safe queries, mutations, and hooks for frameworks like Apollo Client, making it easier and safer to work with GraphQL APIs in your applications. Learn more.

How do I install GraphQL Code Generator for use with Hygraph?

To install GraphQL Code Generator, run npm install graphql and npm install --save-dev @graphql-codegen/cli. Then, initialize the setup with npx graphql-codegen init and follow the prompts to configure your project for Hygraph. See the installation guide for details.

What information do I need to provide during the GraphQL Code Generator setup for Hygraph?

During setup, you'll specify your application type (e.g., React), provide your Hygraph GraphQL endpoint, select plugins (such as TypeScript, TypeScript operations, and TypeScript React Apollo), and configure output file locations and script names. You can use the default options or customize as needed. See the setup walkthrough for step-by-step guidance.

How do I configure queries for use with the code generator and Hygraph?

Create your GraphQL queries (e.g., src/queries/products.graphql) using the Hygraph schema. You can use arguments for filtering, pagination, and ordering. Inspect your Hygraph schema to see available input types. For more, see the configuration section.

How do I use the generated code in my React application?

Import the generated hooks and types (e.g., useAllProductsQuery, ProductOrderByInput) from your output file (such as ./generated/schema.tsx). Use these hooks in your components to fetch and render data with type safety. See the usage example for details.

Can I automate code generation when my queries change?

Yes, you can configure the code generator to watch for changes and automatically regenerate code. This ensures your types and hooks stay up to date as your queries evolve. See the blog post for more information.

Where can I find a complete example of using Hygraph with GraphQL Code Generator?

You can view a full example project on GitHub: hygraph-examples/with-graphql-codegen.

What are the benefits of using GraphQL Code Generator with Hygraph?

Using GraphQL Code Generator with Hygraph saves time by automating code generation, ensures type safety, and reduces manual errors. It also improves developer productivity and makes it easier to maintain large codebases. Read more.

How do I handle fragments and custom types in my queries?

You can define fragments in your query files and import them into your application code. The code generator will create corresponding TypeScript types, ensuring type safety when working with fragments. See the configuration section for examples.

What should I do if I encounter errors during code generation?

Check that your queries are valid and match your Hygraph schema. Ensure all required plugins are installed and your endpoint is correct. For troubleshooting, refer to the Hygraph documentation and the GraphQL Code Generator docs.

How do I connect my Hygraph project to Apollo Client?

Use your Hygraph GraphQL endpoint as the URI in your Apollo Client setup. The generated hooks from GraphQL Code Generator can then be used directly in your React components to fetch and manage data. See the usage section for details.

Can I use environment variables for my Hygraph endpoint?

Yes, you can use environment variables to manage your Hygraph endpoint securely. Update your codegen configuration to reference the environment variable instead of hardcoding the endpoint. This is a best practice for managing sensitive information.

How do I generate type-safe hooks for my queries?

By selecting plugins like TypeScript React Apollo during setup, the code generator will create type-safe hooks (e.g., useAllProductsQuery) that you can use in your React components. This ensures your queries and mutations are strongly typed.

What is the recommended file structure for queries and generated code?

Store your queries in a dedicated folder (e.g., src/queries/) and configure the code generator to output generated code to a separate file (e.g., src/generated/schema.tsx). This keeps your codebase organized and maintainable.

How do I fetch products with specific conditions using Hygraph and GraphQL Code Generator?

Define queries with arguments (e.g., filtering products with no votes) and use the generated hooks to fetch data based on those conditions. See the advanced usage section for examples.

How do I handle loading and error states in my React components?

Use the loading and error properties returned by the generated hooks to conditionally render loading indicators or error messages in your UI. See the usage example for implementation details.

Can I use Hygraph and GraphQL Code Generator with frameworks other than React?

Yes, GraphQL Code Generator supports multiple frameworks and plugins. During setup, select the appropriate plugins for your framework (e.g., Angular, Vue, etc.). Hygraph's GraphQL API can be used with any compatible client.

Where can I find more resources and documentation for Hygraph and GraphQL Code Generator?

Visit the Hygraph Documentation and the GraphQL Code Generator docs for comprehensive guides, API references, and tutorials.

Features & Capabilities

What APIs does Hygraph provide for developers?

Hygraph offers multiple APIs: Content API (read/write), High Performance Content API (low latency, high throughput), MCP Server API (for AI assistants), Asset Upload API, and Management API. Each is designed for specific use cases and can be explored in the API Reference Documentation.

What integrations are available with Hygraph?

Hygraph integrates with leading Digital Asset Management (DAM) systems like Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, and Scaleflex Filerobot. It also supports integrations with Adminix, Plasmic, and custom integrations via SDKs and APIs. Explore more in the Integrations Documentation.

What are the key features and benefits of Hygraph?

Hygraph offers a GraphQL-native architecture, content federation, scalability, enterprise-grade security, user-friendly tools, Smart Edge Cache, localization, and cost efficiency. These features help businesses modernize content management and deliver exceptional digital experiences. Learn more.

How does Hygraph ensure high performance for content delivery?

Hygraph provides high-performance endpoints designed for low latency and high read-throughput. The platform actively measures API performance and offers best practices for optimization. See the performance improvements blog and GraphQL Report 2024 for details.

What technical documentation is available for Hygraph?

Hygraph offers comprehensive documentation covering APIs, schema components, references, webhooks, and AI integrations. Access all resources at the Hygraph Documentation portal.

Pricing & Plans

What pricing plans does Hygraph offer?

Hygraph offers three main plans: Hobby (free forever), Growth (from $199/month), and Enterprise (custom pricing). Each plan includes different features and limits to suit individuals, small businesses, and large enterprises. See the pricing page for details.

What features are included in the Hygraph Hobby plan?

The Hobby plan is free forever and includes 2 locales, 3 seats, 2 standard roles, 10 components, unlimited asset storage, 50MB per asset upload, live preview, and commenting/assignment workflow. Sign up here.

What features are included in the Hygraph Growth plan?

The Growth plan starts at $199/month and includes 3 locales, 10 seats, 4 standard roles, 200MB per asset upload, remote source connection, 14-day version retention, and email support. Get started here.

What features are included in the Hygraph Enterprise plan?

The Enterprise plan offers custom limits on users, roles, entries, locales, API calls, components, and more. It includes advanced features like scheduled publishing, dedicated infrastructure, SSO, multitenancy, instant backup recovery, custom workflows, and dedicated support. Try for 30 days or request a demo.

Security & Compliance

What security and compliance certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3, 2022), ISO 27001 certified, and GDPR compliant. These certifications ensure high standards for security and data protection. Learn more.

How does Hygraph protect my data?

Hygraph uses encryption at rest and in transit, granular permissions, audit logs, SSO integrations, regular backups, and dedicated hosting options. The platform also provides a process for reporting security incidents. Read more.

Use Cases & Success Stories

Who uses Hygraph and for what industries?

Hygraph is used by enterprises, agencies, eCommerce platforms, media companies, technology firms, and global brands. Industries include SaaS, marketplace, education, media, healthcare, consumer goods, automotive, fintech, travel, food, gaming, events, government, electronics, engineering, and construction. See case studies.

What are some notable customer success stories with Hygraph?

Customers like Samsung, Dr. Oetker, Komax, AutoWeb, BioCentury, Vision Healthcare, HolidayCheck, and Voi have achieved faster time-to-market, improved engagement, and reduced costs using Hygraph. Read their stories.

What business impact can I expect from using Hygraph?

Hygraph helps improve operational efficiency, accelerate speed-to-market, reduce costs, enhance scalability, and boost customer engagement. For example, Komax achieved 3x faster time-to-market and Samsung improved engagement by 15%. See more results.

How long does it take to implement Hygraph?

Implementation time varies by project. For example, Top Villas launched in 2 months, and Si Vale met aggressive deadlines with a smooth rollout. Hygraph offers a structured onboarding process and extensive resources to support fast adoption. Read more.

What support and onboarding resources does Hygraph provide?

Hygraph offers a free API playground, developer accounts, structured onboarding (introduction, business, technical, and content kickoffs), webinars, live streams, how-to videos, extensive documentation, and a community Slack channel. Explore resources.

Competition & Differentiation

How does Hygraph compare to traditional CMS platforms?

Hygraph is the first GraphQL-native Headless CMS, offering schema evolution, content federation, and modern workflows. Unlike traditional CMSs that rely on REST APIs and developer intervention, Hygraph enables seamless integration and empowers non-technical users. Compare here.

What makes Hygraph different from other headless CMS solutions?

Hygraph stands out with its GraphQL-native architecture, content federation, Smart Edge Cache, and focus on enterprise-grade security and compliance. It is recognized for ease of implementation and scalability, ranking 2nd out of 102 Headless CMSs in the G2 Summer 2025 report. See ranking.

Why should I choose Hygraph over alternatives?

Hygraph offers unique advantages such as GraphQL-native design, content federation, enterprise-grade features, user-friendly tools, scalability, proven ROI, and market recognition. Case studies show 3x faster time-to-market and improved engagement for customers like Komax and Samsung. See why.

Customer Experience & Feedback

What do customers say about the ease of use of Hygraph?

Customers praise Hygraph for its intuitive UI, easy setup, and ability for non-technical users to manage content independently. Real-time changes and custom app integrations enhance the experience. Some users note a learning curve for complex use cases. Read feedback.

What pain points does Hygraph solve for its customers?

Hygraph addresses operational inefficiencies (developer dependency, legacy tech), financial challenges (high costs, slow launches), and technical issues (schema evolution, integration, performance, localization). See case studies for real-world examples.

How does Hygraph help with schema evolution and type safety?

Hygraph's GraphQL-native architecture and integration with tools like GraphQL Code Generator simplify schema evolution and ensure type safety, reducing boilerplate and manual errors for developers. Learn more.

Introducing Click to Edit

Working with GraphQL Code Generator and Hygraph

In this post I'll show how you can install, configure, and generate your first query with Apollo Client using GraphQL Code Generator.
Jamie Barton

Written by Jamie 

Jun 14, 2021
 GraphQL Code Generator and Hygraph with Apollo Client

GraphQL Code Generator is an awesome open source project by The Guild that generates code from your Hygraph schema.

In this post I'll show how you can install, configure, and generate your first query with Apollo Client using GraphQL Code Generator. This post assumes you are using React, and have Apollo Client already setup.

#Install

First, let's begin by installing graphql and @graphql-codegen/cli.

npm install graphql
npm install --save-dev @graphql-codegen/cli

Next, run the initialization wizard.

npx graphql-codegen init

You'll be asked a series of questions:

What type of application are you building? Feel free to pick the relevant one, I'll be using React through this post.

Where is your schema? You'll want to enter your Hygraph endpoint here. For example, https://api-eu-central-1.hygraph.com/v2/ck8sn5tnf01gc01z89dbc7s0o/master

You can follow this article by using the same endpoint if you don't have a project setup already.

You can later change this to be an ENV variable.

Where are your operations and fragments? If you haven't any existing GraphQL queries, mutations, or fragments defined in your project, just hit enter to accept the default.

Pick plugins Now you'll want to select the plugins, we'll go ahead and pick TypeScript, TypeScript operations, and TypeScript React Apollo.

Where to write the output? This is where the generated code is output. Since we used TypeScript allow, the file extension will be .tsx - as it includes Apollo Client hooks.

Do you want to generate an introspection file? Yes we do!

How to name the config file? The default codegen.yml is good - unless you have a strong preference otherwise.

What script in package.json should run the codegen? Personally I like just calling it codegen.

Now we'll need to install the plugins we selected:

npm install

Once everything is installed, you'll need to have some queries before try to generate any code!

#Configure

Let's create a simple query inside src/queries/products.graphql:

query allProducts(
$orderBy: ProductOrderByInput
$first: Int
$skip: Int
$where: ProductWhereInput
) {
products(orderBy: $orderBy, first: $first, skip: $skip, where: $where) {
...ProductSummary
}
}
fragment ProductSummary on Product {
id
name
slug
description
publishedAt
}

This query uses arguments for filtering, paginating, and ordering your products. You can inspect your Hygraph GraphQL schema to see all possible input types for your own GraphQL types.

Now we've a GraphQL query, we can go ahead and run the code generator:

npm run codegen # or whatever the script was you named

You should now see the file src/generated/schema.tsx (if you kept the default output filename), and inside here if you scroll to the bottom, there will be some generated Apollo Client hooks.

Repeat this for any GraphQL queries, or mutations you use within your application. You can also "watch" for any changes, and automatically run the code generator!

#Usage

Now we'll use the automatically generated query inside our code. Inside your application, import the hook, and input type to better type your page.

import {
useAllProductsQuery,
ProductOrderByInput,
} from './generated/schema.tsx';

Then invoke the useAllProductsQuery hook and pass it some variables to order the results.

const { loading, error, data } = useAllProductsQuery({
variables: { orderBy: ProductOrderByInput.PublishedAtDesc },
});

As you can see, we're using the auto generated value for PublishedAtDesc from the schema for ultimate type safety.

Next, let's render loading if we're loading, and render that we have an error if one is defined.

if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;

Then on your page render the list of products if we've got data:

<ul>
{data &&
data.products.map((product) => (
<li key={product.id}>{product.name}</li>
))}
</ul>

If you type the above without copy/pasting, you'll notice the autosuggest for [product.id](http://product.id) and [product.name](http://product.name) - this is based off the fragment we defined earlier. ✨

#Going further

With the example schema I shared above, products have a relation to votes. A product can have many votes.

Let's now write a query inside our application that fetches products where there are no votes. We'll need to import ProductSummaryFragment so we can properly type our function.

import { ProductSummaryFragment } from './generated/schema.tsx';
function useOneProductWithoutVote(): ProductSummaryFragment | undefined {
const { data } = useAllProductsQuery({
variables: { where: { votes_none: {} }, first: 1 },
});
return data?.products[0];
}

We can then invoke this function:

const { loading, error, data } = useAllProductsQuery({
variables: { orderBy: ProductOrderByInput.PublishedAtDesc },
});
const aProductWithoutVote = useOneProductWithoutVote();
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return (
<>
<h2>Our products</h2>
<ul>
{data &&
data.products.map((product) => (
<li key={product.id}>{product.name}</li>
))}
</ul>
{aProductWithoutVote && (
<>
<h2>Don't forget to vote on: </h2>
<p>{aProductWithoutVote.name}</p>
</>
)}
</>
);

Hopefully you've found this article useful in getting started with Hygraph + GraphQL Code Generator. GraphQL Code Generator not only saves you a lot of time by automatically generating code, but it generates code that is type safe.

You can view the code for this example on GitHub.

Blog Author

Jamie Barton

Jamie Barton

Jamie is a software engineer turned developer advocate. Born and bred in North East England, he loves learning and teaching others through video and written tutorials. Jamie currently publishes Weekly GraphQL Screencasts.

Share with others

Sign up for our newsletter!

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