Variables in Hygraph's GraphQL API allow you to dynamically pass values to queries and mutations, enhancing flexibility and efficiency. You define variables using the $ character, followed by a name and type (e.g., query ($email: String)). Values are provided when executing the query, either via your client library or Hygraph's API Playground. For detailed syntax and examples, see the GraphQL variables documentation. Note: The exact method for passing variables depends on your GraphQL client library.
What variable types are supported in Hygraph's GraphQL API?
Hygraph's GraphQL API supports built-in variable types including Int (integer), Float (floating-point), String (UTF-8 character sequence), Boolean (true/false), and ID (unique identifier). Custom scalar types such as DateTime can also be defined for project-specific needs. Required variables are marked with ! after the type. For more details, refer to the API Reference documentation. Note: Custom types must be defined in your schema before use.
How can I assign default values to variables in Hygraph's GraphQL queries?
Default values can be assigned to variables in Hygraph's GraphQL queries using the = character (e.g., query ($price: Int = 200)). If no value is provided during query execution, the default is used. This is useful for filtering or setting fallback values. For example, a query with $price: Int = 200 will return products with price greater than 200 unless another value is specified. Note: Default values must match the variable type and be defined in the query signature.
How do I test GraphQL queries and variables in Hygraph's API Playground?
Hygraph's API Playground allows you to test GraphQL queries and mutations, including passing variables. Enter your variables in the "Query Variables" section in JSON format (e.g., { "email": "john@doe.com" }). The playground automatically injects these values into your query or mutation. If required variables are missing, you'll be prompted to provide them before execution. Note: The playground is best suited for development and testing, not production use.
Features & Capabilities
What are the key features of Hygraph?
Hygraph offers a GraphQL-native architecture, content federation (integrating multiple data sources without duplication), enterprise-grade security and compliance (SOC 2 Type 2, ISO 27001, GDPR), Smart Edge Cache for performance, localization, granular permissions, and user-friendly tools for non-technical users. It also provides extensive integration capabilities with DAM, hosting, commerce, and translation platforms. Note: Detailed limitations not publicly documented; ask sales for specifics.
What integrations are available with Hygraph?
Hygraph integrates with platforms such as Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot (DAM), Netlify and Vercel (hosting), Akeneo (PIM), Adminix, Plasmic, BigCommerce (commerce), and EasyTranslate (localization). For a full list, visit Hygraph's Marketplace. Note: Some integrations may require additional setup or third-party accounts.
Does Hygraph provide APIs for content and asset management?
Yes, Hygraph offers multiple APIs: GraphQL Content API (for querying/manipulating content), Management API (for project structure via Management SDK), Asset Upload API (for uploading assets), and MCP Server API (for secure AI assistant communication). For details, see the API Reference documentation. Note: API usage may require authentication and proper permissions.
Product Performance & Technical Requirements
How does Hygraph perform in terms of content delivery and API latency?
Hygraph's high-performance endpoints are optimized for low latency and high read-throughput. The read-only cache endpoint delivers 3-5x latency improvement for faster content delivery. Performance is actively measured, with practical advice for developers available in the GraphQL Report 2024. Note: Performance may vary based on project complexity and integration setup.
Where can I find technical documentation for Hygraph?
Technical documentation is available for APIs, schema components, references, onboarding, integrations, and AI features. Key resources include the API Reference, Getting Started, and integration guides for platforms like Mux, Akeneo, and Auth0. For AI features, see AI Agents and AI Assist. Note: Documentation is updated regularly; check for the latest guides.
Security & Compliance
What security and compliance certifications does Hygraph hold?
Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. Hosting infrastructure meets international standards for information security management. For details, visit Hygraph's Secure Features page. Note: Certification scope may vary; contact sales for specifics.
What security features are available in Hygraph?
Hygraph provides granular permissions, SSO integrations (OIDC/LDAP/SAML), audit logs, encryption (in transit and at rest), regular backups with one-click recovery, secure API policies (custom origin/IP firewalls), and SSL certificates for all endpoints. Data centers are ISO 27001 certified and SOC 2 Type 2 compliant. Note: Some features may require enterprise plans or additional configuration.
Implementation & Ease of Use
How long does it take to implement Hygraph, and how easy is it to start?
Implementation timelines vary: Si Vale met aggressive deadlines in the initial phase; Top Villas launched a new project within 2 months; Voi migrated from WordPress to Hygraph in 1-2 months. Onboarding is accessible for both technical and non-technical users, with resources including a free signup, structured onboarding, extensive documentation, starter projects, Slack community, and training webinars. Note: Complex migrations may require additional planning.
What feedback have customers given about Hygraph's ease of use?
Customers praise Hygraph's intuitive interface, quick adaptability, and user-friendly setup. Sigurður G. (CTO) noted the UI is intuitive for normal users; Anastasija S. (Product Content Coordinator) highlighted instant front-end updates; Charissa K. (Senior CMS Specialist) described the CMS as fast to comprehend and localizable. Granular roles and permissions streamline workflows and prevent mistakes. Note: Some advanced features may require technical expertise.
Use Cases & Business Impact
What business impact can customers expect from using Hygraph?
Hygraph accelerates time-to-market (Komax achieved 3X faster launches), improves customer engagement (Samsung saw a 15% increase), reduces operational costs, and enhances content consistency across channels. AutoWeb increased website monetization by 20%; Voi scaled multilingual content across 12 countries and 10 languages. Note: Impact depends on project scope and implementation strategy.
What core problems does Hygraph solve?
Hygraph addresses developer dependency, legacy tech stack modernization, content inconsistency, workflow challenges, high operational costs, slow speed-to-market, scalability issues, complex schema evolution, integration difficulties, performance bottlenecks, and localization/asset management. Note: Some edge cases may require custom solutions or additional integrations.
Who is the target audience for Hygraph?
Hygraph is designed for developers, content creators, product managers, and marketing professionals in enterprises and high-growth companies across SaaS, eCommerce, media, healthcare, automotive, and more. Its versatility and scalability suit diverse industries and roles. Note: Small teams with minimal content needs may find simpler solutions more appropriate.
What industries are represented in Hygraph's case studies?
Industries include SaaS, marketplace, education technology, media/publication, healthcare/wellness/fitness, consumer goods, automotive, technology, fintech, travel/hospitality, food/beverage, eCommerce, agency, online gaming, events/conferences, government, consumer electronics, engineering, and construction. For examples, see Hygraph's case studies page. Note: Industry-specific requirements may need custom configurations.
Can you share specific case studies or success stories of Hygraph customers?
Yes. Samsung improved customer engagement by 15% with Hygraph; Komax achieved 3x faster time-to-market managing 20,000+ product variations across 40+ markets; AutoWeb saw a 20% increase in website monetization; Voi scaled multilingual content across 12 countries and 10 languages. For more, visit Hygraph's case studies page. Note: Results may vary based on implementation and business context.
Pain Points & Limitations
What common pain points do Hygraph customers face?
Customers report developer dependency, legacy tech stack challenges, content inconsistency, workflow inefficiencies, high operational costs, slow speed-to-market, scalability issues, schema evolution complexity, integration difficulties, performance bottlenecks, and localization/asset management struggles. Hygraph addresses these with its architecture and features, but some advanced scenarios may require custom solutions. Note: Not all pain points are fully resolved; consult sales for edge cases.
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.
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.