Frequently Asked Questions

GraphQL Variables & Usage

What are GraphQL variables and why are they useful?

GraphQL variables allow you to dynamically pass values to your queries and mutations, making your operations more flexible and efficient. They help you avoid hardcoding values and enable you to reuse queries with different inputs. Learn more.

How do I define and use variables in a GraphQL query?

Variables are defined using the $ character, followed by a name and a type. For example: query ($email: String) { orders(where: {email: $email}) { id email } }. You provide values for these variables when executing the query. See the Hygraph GraphQL Variables tutorial for examples.

What types of variables does GraphQL support?

GraphQL supports built-in types such as Int, Float, String, Boolean, and ID. You can also define custom scalar types, like DateTime in Hygraph projects. Read more.

How do I make a variable required in GraphQL?

To make a variable required, add an exclamation mark (!) after its type (e.g., $name: String!). If you do not provide a value for a required variable, the query or mutation will return an error.

Can I assign default values to GraphQL variables?

Yes, you can assign default values to variables using the = character (e.g., query ($price: Int = 200)). If no value is provided, the default is used during query execution.

How do I pass variables in Hygraph's GraphQL Playground?

In Hygraph's API Playground, you can pass variables by switching to the Query Variables section and entering them in JSON format. These values are automatically injected into your query or mutation. Try it here.

What happens if I omit a required variable in a GraphQL query?

If you omit a required variable (one marked with !), the query or mutation will return an error and prompt you to provide the missing variable.

How do I use variables in GraphQL mutations?

You define variables in the mutation signature and reference them in the mutation body. For example, mutation createProduct($name: String!, $price: Int!) { createProduct(data: { name: $name, price: $price }) }. Required variables must be provided when executing the mutation.

Can I use custom scalar types as variables in Hygraph?

Yes, Hygraph supports custom scalar types such as DateTime, allowing you to pass date and time values as variables in your queries and mutations.

How do I pass variables using Apollo Client with Hygraph?

With Apollo Client, you define your query with variables and pass them as an object in the useQuery hook. For example: useQuery(GET_ORDERS, { variables: { email: 'john@doe.com' } }). See the tutorial for more details.

Where can I find more resources on using GraphQL with Hygraph?

You can explore the GraphQL Variables tutorial, Hygraph Documentation, and the Hygraph Blog for more guides and best practices.

How do I get started with Hygraph and GraphQL variables?

Sign up for a Hygraph account, select a template (like the Commerce Shop), and follow the prompts to create your project. You can then access your GraphQL endpoint and start experimenting with variables. Get started here.

What is the syntax for passing variables in the Hygraph API Playground?

Variables are passed in JSON format in the Query Variables section. For example: { "email": "john@doe.com" }. These are injected into your query or mutation automatically.

What happens if I provide no value for an optional variable?

If you do not provide a value for an optional variable, the default value (if specified) is used, or the field is omitted from the query or mutation execution.

Can I use variables to filter data in Hygraph queries?

Yes, you can use variables to filter data dynamically in your queries. For example, you can filter products by price or orders by email using variables.

Are there best practices for using variables in GraphQL with Hygraph?

Best practices include using variables for dynamic values, marking required variables appropriately, and assigning default values where helpful. Refer to the Hygraph tutorial for examples.

Can I use variables in both queries and mutations in Hygraph?

Yes, variables can be used in both queries and mutations to make your operations more dynamic and reusable.

How do I troubleshoot errors related to missing variables in Hygraph?

If you encounter errors about missing variables, ensure all required variables are provided and match the expected types. The Hygraph API Playground will prompt you for missing required variables before execution.

What is the benefit of using variables instead of hardcoded values in GraphQL?

Using variables makes your queries and mutations reusable, more secure, and easier to maintain, as you avoid hardcoding values directly in your operations.

Features & Capabilities

What features does Hygraph offer for content management?

Hygraph provides a GraphQL-native architecture, content federation, user-friendly tools, enterprise-grade security, Smart Edge Cache, localization, asset management, and extensive integration options. See all features.

Does Hygraph support high-performance content delivery?

Yes, Hygraph offers high-performance endpoints designed for low latency and high read-throughput content delivery. Performance is actively measured and optimized. Read more.

What integrations are available with Hygraph?

Hygraph integrates with DAM systems (Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), Adminix, Plasmic, and supports custom integrations via SDKs and APIs. Explore the Hygraph Marketplace for more.

Does Hygraph provide an API?

Yes, Hygraph offers multiple APIs: Content API, High Performance Content API, MCP Server API, Asset Upload API, and Management API. See API documentation.

What technical documentation is available for Hygraph?

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

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 support levels. See pricing 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 workflow. Learn more.

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. See details.

What features are included in the Hygraph Enterprise plan?

The Enterprise plan offers custom limits, advanced governance, scheduled publishing, dedicated infrastructure, SSO, multitenancy, instant backup recovery, custom workflows, and dedicated support. See all features.

Security & Compliance

What security certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3, 2022), ISO 27001 certified, and GDPR compliant. See security details.

How does Hygraph ensure data security and compliance?

Hygraph uses granular permissions, audit logs, SSO integrations, encryption at rest and in transit, regular backups, and ISO 27001-certified providers. Learn more.

Use Cases & Benefits

Who can benefit from using Hygraph?

Hygraph is ideal for developers, product managers, content creators, marketers, solutions architects, enterprises, agencies, eCommerce, media, technology companies, and global brands. See case studies.

What business impact can I expect from using Hygraph?

Customers report improved operational efficiency, faster speed-to-market, cost savings, enhanced scalability, and better customer engagement. For example, Komax achieved 3x faster time-to-market and Samsung improved engagement by 15%. Read more.

What industries use Hygraph?

Hygraph is used in SaaS, marketplaces, edtech, media, healthcare, consumer goods, automotive, fintech, travel, food & beverage, eCommerce, agencies, gaming, events, government, consumer electronics, engineering, and construction. See all industries.

Can you share some customer success stories with Hygraph?

Yes. Samsung built a scalable API-first app, Komax achieved 3x faster launches, AutoWeb saw a 20% increase in monetization, and Voi scaled content across 12 countries. Read case studies.

Implementation & Support

How long does it take to implement Hygraph?

Implementation time varies, but Top Villas launched in just 2 months and Si Vale met aggressive deadlines. Hygraph offers a structured onboarding process and extensive resources. See example.

How easy is it to get started with Hygraph?

Hygraph offers a free API playground, free developer accounts, structured onboarding, training resources, and a community Slack channel for support. Explore documentation.

What feedback have customers given about Hygraph's ease of use?

Customers praise Hygraph's intuitive UI, ease of setup, and ability for non-technical users to manage content independently. Some users note a learning curve for complex use cases. Read feedback.

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. It reduces developer dependency and operational costs compared to traditional CMSs. See comparison.

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 user-friendly tools for both technical and non-technical users. It ranked 2nd out of 102 Headless CMSs in G2's Summer 2025 report. See ranking.

Introducing Click to Edit

GraphQL

Variables

In this tutorial, we will look at GraphQL variables, how to use them in queries and mutations, different variable types, and assigning default and required variables.

One feature that makes GraphQL more flexible and powerful is its support for variables. By the end of this tutorial, you should have a solid understanding of how to use variables in GraphQL effectively and take advantage of their benefits.

Getting Started

Before diving into variables, we must set up our environment. For this tutorial, we will be using the Hygraph Commerce Shop template. You can clone this template and retrieve your GraphQL endpoint by following these steps:

Sign up for a Hygraph account and log in to the dashboard. Select the Commerce Shop Template and follow the prompts to create your project. Once your project is created, navigate to the Project settings section in the dashboard and copy your Content API endpoint.

ecommerce template in hygraph

With our Hygraph Commerce Shop project set up and our GraphQL endpoint retrieved, we are ready to explore variables in GraphQL.

Try Hygraph, the GraphQL native headless CMS

Build limitless solutions rapidly with our GraphQL-native API-first approach

How to Use Variables in GraphQL

Variables allow you to dynamically pass values to your queries and mutations, thereby enhancing the power and efficiency of these operations.

Syntax and Structure of GraphQL Variables

GraphQL variables are defined using the $ character, followed by a name and a type. For example, to define a variable for the email field of an order list, we would use the following syntax:

query ($email: String) {
orders(where: {email: $email}) {
id
email
stage
total
}
}

We would then provide a value for the variable when we execute the query. For example, to retrieve all orders with the email address john@doe.com, we would provide the following value for the email variable:

{
"email": "john@doe.com"
}

The exact way to pass variables in a query depends on the GraphQL client library that you are using. For example, if you are using the Apollo client, you can pass variables as follows:

import { gql, useQuery } from "@apollo/client";
const GET_ORDERS = gql`
query ($email: String) {
orders(where: { email: $email }) {
id
email
stage
total
}
}
`;
const { data } = useQuery(GET_ORDERS, {
variables: { email: "john@doe.com" },
});

Variable Types

GraphQL supports several built-in variable types, including:

  • Int: a signed 32-bit integer
  • Float: a signed double-precision floating-point value
  • String: a UTF‐8 character sequence
  • Boolean: true or false
  • ID: a unique identifier, often used as a primary key

In addition to these built-in types, GraphQL allows custom scalar types to be defined, providing flexibility in the types of values that can be passed as variables. For example, our Hygraph Commerce project custom types like DateTime, which allows date and time values to be passed as variables.

Required Variables

We can mark a variable as required by adding the ! character after its type. If we do not provide a value for a required variable when we execute a query or mutation, the query or mutation will return an error.

Here's an example of a mutation that requires four variables, name, price, description, and slug, while the createdAt field is optional.

mutation createProduct(
$name: String!
$price: Int!
$description: String!
$slug: String!
$createdAt: DateTime
) {
createProduct(
data: {
name: $name
price: $price
description: $description
slug: $slug
createdAt: $createdAt
}
)
}

When executing this mutation, we must provide values for the required variables; otherwise, we will receive an error. However, the $createdAt variable is optional, and its absence won't affect the mutation's execution.

Running the mutation on Hygraph API Playground

Assigning Default Values to Variables

We can also assign default values to variables, which will be used if no value is provided when the query or mutation is executed. To do this, we use the = character followed by the default value.

For example, if we would like to load products with a price greater than 200, we could use the following query syntax:

query ($price: Int = 200) {
products(where: {price_gt: $price}) {
id
name
price
description
publishedAt
}
}

In this query, the where argument is used to filter products where the price field is greater than the value of the price variable. The $price variable has a default value of 200, which means that if no value is explicitly passed during query initialization, the query will always return products with a price greater than 200.

Passing Variables via Hygraph's GraphQL Playground

Hygraph's API playground facilitates testing GraphQL queries and mutations, including the ability to pass variables. To pass variables through this interface, switch to the Query Variables section on the right-hand side, as shown below.

hygraph-s graphql playground.png

Next, enter the variable(s) and their corresponding values in JSON format. For example:

{
"email": "john@doe.com"
}

The values from the "Query Variables" section will be automatically injected into your query or mutation. If any required variables are missing, you will be prompted to provide them before executing the query or mutation.

Conclusion

In this tutorial, we learned GraphQL variables and how to use them in queries and mutations and demonstrated their usage with Hygraph. Using variables can make our queries and mutations more powerful and efficient.