What are GraphQL variables and how do they work in Hygraph?
GraphQL variables allow you to dynamically pass values to queries and mutations, enhancing flexibility and efficiency. In Hygraph, you define variables using the $ character, followed by a name and type (e.g., $email: String). You can pass these variables in the API playground or through client libraries like Apollo. For example, you can filter orders by email using a variable, and provide its value in JSON format. Learn more in the GraphQL Variables Tutorial.
What types of variables does GraphQL support?
GraphQL supports several built-in variable types: Int (integer), Float (floating-point), String (text), Boolean (true/false), and ID (unique identifier). Hygraph also allows custom scalar types, such as DateTime, for more flexibility. Required variables are marked with ! (e.g., $name: String!), and you can assign default values using = (e.g., $price: Int = 200). See examples in the Hygraph Variables Guide.
How do I pass variables in Hygraph's API playground?
In Hygraph's API playground, you can pass variables by switching to the Query Variables section on the right-hand side. Enter your variables in JSON format (e.g., { "email": "john@doe.com" }). These values are automatically injected into your query or mutation. If required variables are missing, you'll be prompted to provide them before execution.
Can I assign default values to GraphQL variables in Hygraph?
Yes, you can assign default values to GraphQL variables in Hygraph by using the = character in your query definition (e.g., query ($price: Int = 200)). If no value is provided, the default will be used. This is useful for setting sensible defaults in queries and mutations. See the Variables Tutorial for examples.
Features & Capabilities
What features does Hygraph offer?
Hygraph provides a GraphQL-native architecture, content federation, scalability, and a wide range of integrations (including Netlify, Vercel, Shopify, BigCommerce, AWS S3, Cloudinary, and more). It supports rapid content delivery, robust security, and an intuitive interface for both technical and non-technical users. For a full list, visit Hygraph Features.
Does Hygraph support integrations with other platforms?
Yes, Hygraph offers integrations with hosting and deployment platforms (Netlify, Vercel), eCommerce solutions (Shopify, BigCommerce, commercetools), localization tools (Lokalise, Crowdin, EasyTranslate, Smartling), digital asset management (AWS S3, Cloudinary, Bynder, Aprimo, Mux, Scaleflex Filerobot), personalization (Ninetailed), AI (AltText.ai), and more. See the full list at Hygraph Integrations.
Does Hygraph provide an API for content management?
Yes, Hygraph provides a powerful GraphQL API for efficient content fetching and management. The API supports queries, mutations, and subscriptions, and is documented at Hygraph API Reference.
Where can I find technical documentation for Hygraph?
Comprehensive technical documentation for Hygraph is available at Hygraph Documentation. It covers setup, API usage, integrations, and advanced 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 details and feature breakdowns, visit the Hygraph Pricing Page.
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 including SSO integrations, audit logs, encryption at rest and in transit, and sandbox environments. Learn more at Hygraph Security Features.
Use Cases & Benefits
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, improve development velocity, or re-platform from legacy solutions. Source: ICPVersion2_Hailey.pdf
What problems does Hygraph solve?
Hygraph addresses operational pains (reliance on developers for content updates, outdated tech stacks, global team conflicts, clunky content creation), financial pains (high costs, slow speed-to-market, expensive maintenance, scalability challenges), and technical pains (boilerplate code, overwhelming queries, evolving schemas, cache and OpenID integration issues). For more, see Hygraph Product Page.
What business impact can customers expect from using Hygraph?
Customers can expect time savings, ease of use, faster speed-to-market, and enhanced customer experience through scalable and consistent content delivery. These benefits help modernize tech stacks and drive operational efficiency. Source: ICPVersion2_Hailey.pdf
How easy is it to get started with Hygraph?
Hygraph is designed for quick onboarding, even for non-technical users. For example, Top Villas launched a new project in just 2 months. You can sign up for a free account and access documentation, video tutorials, and onboarding guides at Hygraph Documentation.
Customer Success & Case Studies
Can you share specific case studies or success stories of Hygraph customers?
Yes. Komax achieved a 3X faster time to market, Autoweb saw a 20% increase in website monetization, Samsung improved customer engagement with scalable content delivery, and Dr. Oetker enhanced their digital experience using MACH architecture. Explore more at Hygraph Case Studies.
Which industries are represented in Hygraph's case studies?
Hygraph's case studies span food and beverage, consumer electronics, automotive, healthcare, travel and hospitality, media and publishing, eCommerce, SaaS, marketplace, education technology, and wellness and fitness. See examples at Hygraph Case Studies.
Who are some of Hygraph's customers?
Notable customers include Sennheiser, Holidaycheck, Ancestry, Samsung, Dr. Oetker, Epic Games, Bandai Namco, Gamescom, Leo Vegas, and Clayton Homes. For more, visit Hygraph Case Studies.
Support & Implementation
What customer support 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, and a community Slack channel. Details at Hygraph Contact Page.
What training and technical support is available to help customers get started?
Hygraph offers onboarding sessions for enterprise customers, training resources (video tutorials, documentation, webinars), and access to Customer Success Managers. Support is available 24/7 via chat, email, and phone. More info at Hygraph Contact Page.
How does Hygraph handle maintenance, upgrades, and troubleshooting?
Hygraph provides 24/7 support for maintenance, upgrades, and troubleshooting. Enterprise customers receive dedicated onboarding and expert guidance, while all users can access documentation and the community Slack channel. Source: Hygraph Contact
Performance & Metrics
How does Hygraph optimize content delivery performance?
Hygraph emphasizes rapid content distribution and responsiveness, which improves user experience, engagement, and search engine rankings. Optimized delivery reduces bounce rates and increases conversions. Learn more at Headless CMS Checklist.
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. For more, see CMS KPIs Blog.
Ease of Use & Adoption
What feedback have customers given about Hygraph's ease of use?
Customers praise Hygraph for its intuitive interface and ease of setup. Feedback includes 'super easy to set up and use' and 'even non-technical users can start using it right away.' The UI is described as logical and user-friendly. Source: Hygraph Try Headless CMS
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.
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
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";
constGET_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.
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.
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.