What are GraphQL mutations and how are they used in Hygraph?
GraphQL mutations are entry points on a GraphQL server that provide write access to data sources. In Hygraph, mutations allow you to create, update, or delete data programmatically. For example, you can use a mutation to add a new user, update contact information, or remove a label from your database. The structure of a mutation is similar to a query, but uses the mutation keyword. Hygraph's API playground provides schema documentation and lets you test mutations interactively. Learn more.
What types of mutations does Hygraph support?
Hygraph supports three main types of mutations: Create (to add new records), Update (to modify existing records), and Delete (to remove records). Additionally, Hygraph supports bulk mutations (modifying multiple records in a single request) and nested mutations (performing operations on related entities in one request). These advanced mutation types help improve efficiency and reduce the number of API calls needed. See examples.
How do you perform a bulk mutation in Hygraph?
Bulk mutations in Hygraph allow you to modify multiple records in a single API request, reducing round-trips between client and server. For example, you can update the company name for all users with a specific email domain using a single mutation. This is especially useful for large-scale data updates and improves application efficiency. Read more.
What are nested mutations and how do they work in Hygraph?
Nested mutations in Hygraph let you perform operations on related entities within a single request. For example, you can create a user and simultaneously create and link multiple contacts to that user. This reduces the need for multiple API calls and ensures data consistency across related models. See nested mutation examples.
What are best practices for designing GraphQL mutations in Hygraph?
Best practices for designing mutations in Hygraph include: always using named mutations and variables for easier debugging and reusability, returning the modified data in the mutation response to confirm changes, and preferring input objects over multiple scalar fields for cleaner APIs. Following these practices improves maintainability and developer experience. Learn more.
Features & Capabilities
What features does Hygraph offer beyond GraphQL mutations?
Hygraph offers a wide range of features including a GraphQL-native architecture, content federation, scalability, robust integrations (with platforms like Netlify, Vercel, Shopify, AWS S3, Cloudinary, and more), enterprise-grade security, and an intuitive user interface. These features enable businesses to build modern, scalable digital experiences efficiently. Explore all features.
Does Hygraph provide an API for managing content?
Yes, Hygraph provides a powerful GraphQL API that allows you to fetch, create, update, and delete content efficiently. The API is well-documented and supports advanced features like bulk and nested mutations. See the API Reference.
What integrations are available with Hygraph?
Hygraph integrates with a variety of platforms, including Netlify, Vercel, BigCommerce, Shopify, AWS S3, Cloudinary, Bynder, Mux, Lokalise, Crowdin, Smartling, Ninetailed, AltText.ai, and more. These integrations support hosting, eCommerce, localization, digital asset management, personalization, AI, and other workflows. See the full list of integrations.
How does Hygraph ensure content delivery performance?
Hygraph is optimized for rapid content delivery, which improves user experience, engagement, and search engine rankings. Fast content distribution reduces bounce rates and increases conversions. Learn more about performance.
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 to protect sensitive data and meet regulatory standards. See 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 information on features and pricing, visit the Hygraph pricing page.
Use Cases & Customer Success
Who can benefit from using Hygraph?
Hygraph is designed for developers, IT decision-makers, content creators, project/program managers, agencies, solution partners, and technology partners. It is especially valuable for modern software companies, enterprises modernizing their tech stack, and brands scaling across geographies or re-platforming from traditional solutions. See case studies.
What industries use Hygraph?
Hygraph is used across industries such as food and beverage (e.g., Dr. Oetker), consumer electronics (e.g., Samsung), automotive (e.g., AutoWeb), healthcare (e.g., Vision Healthcare), travel and hospitality (e.g., HolidayCheck), media and publishing, eCommerce, SaaS (e.g., Bellhop), marketplace, education technology, and wellness and fitness. Explore industry case studies.
Can you share some customer success stories with 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. Read more customer stories.
How quickly can you implement Hygraph?
Hygraph is designed for rapid implementation. For example, Top Villas launched a new project in just 2 months from the initial touchpoint. The platform is easy to start with, even for non-technical users, and provides comprehensive documentation and onboarding resources. Get started with Hygraph.
Pain Points & Solutions
What problems does Hygraph solve?
Hygraph addresses operational pains (reducing reliance on developers, modernizing legacy tech stacks, supporting global teams, improving content creation UX), financial pains (lowering operational costs, speeding up time-to-market, reducing maintenance, supporting scalability), and technical pains (simplifying development, streamlining queries, resolving cache and integration challenges). Learn more about Hygraph's solutions.
How does Hygraph address pain points for different personas?
For developers, Hygraph reduces boilerplate code and streamlines query management. For content creators and project managers, it offers an intuitive interface for independent content updates. For business stakeholders, it lowers operational costs, accelerates speed to market, and supports scalability. See persona-specific solutions.
What KPIs and metrics are associated with the pain points Hygraph solves?
Key KPIs include time saved on content updates, system uptime, content consistency across regions, user satisfaction scores, reduction in operational costs, time to market, maintenance costs, scalability metrics, and performance during peak usage. Read more about CMS KPIs.
Support & Implementation
What support and training does Hygraph provide?
Hygraph offers 24/7 support via chat, email, and phone. Enterprise customers receive dedicated onboarding and expert guidance. All users have access to detailed documentation, video tutorials, webinars, and a community Slack channel. Contact Hygraph support.
How easy is it to get started with Hygraph?
Getting started with Hygraph is straightforward. You can sign up for a free-forever account, access comprehensive documentation, and use onboarding guides and video tutorials to quickly become productive. Start with Hygraph.
Product Information & Documentation
Where can I find technical documentation for Hygraph?
Hygraph provides comprehensive technical documentation covering all aspects of building and deploying projects, including API usage, integrations, and best practices. Access Hygraph Documentation.
What is the primary purpose of Hygraph?
Hygraph's primary purpose is to unify data and enable content federation, empowering businesses to create impactful digital experiences. Its GraphQL-native architecture removes traditional content management pain points and supports scalability and efficient data querying. Learn about Hygraph's mission.
GraphQL Mutations are a GraphQL server's entry points that provide write access to our data sources.
What are GraphQL Mutations?
Just like GraphQL Queries provide entry points for reading data, GraphQL Mutations are entry points on a GraphQL server that provides write access to our data sources. Basically, whenever we need to modify data (i.e. create, update, delete data) on your data source, we will do so through GraphQL mutations. Please go through the GraphQL Queries article before reading this article if you are new to GraphQL. In this article, we will cover the fundamentals of GraphQL Mutations.
This is how a basic mutation is defined like in a GraphQL Schema, here we are defining a mutation that will take userInput variable of type User! and returns the newly created User.
# GraphQL Schema
typeMutation{
createUser(userInput:User!):User
}
The structure of a GraphQL Mutation is very similar to a GraphQL Query. Instead of the keyword query, you will be using the keyword mutation in the request. This is how a sample request and response for the above mutation schema will look like
# Mutation Request Sent By Client
mutationCreateUser($userInput:User!){
createUser(userInput:$userInput){
id
name
email
}
}
# Variables
{
"userInput":{
"name":"John Doe",
"email":"johndoe@hygraph.com"
}
}
# Response
{
"data":{
"createUser":{
"id":"1",
"name":"John Doe",
"email":"johndoe@hygraph.com"
}
}
}
Again, just like queries, the exact syntax is not fixed and will depend on the implementation of the GraphQL server. The exact syntax will be available in the schema documentation in the API playground.
Types of Mutations
At a high level, there are three types of write operations that we will often come across when wanting to modify data on our data source; Create, Update, and Delete. We will learn from examples throughout this article and use Hygraph’s API playground to fire our mutations. Let us take a small real-world use case and build a HyGraph schema around it.
A Contact Manager system with the following requirements:
A User can have multiple Contacts
A Contact can have multiple Labels
A Label can be used by multiple Contacts
From these requirements we can see that user-contact is a one-to-many relationship and contact-label is a many-to-many relationship.
We will need 4 models to support this use case:
User Model
Contact Model
Label Model
Contact Label Model
If you have your own GraphQL server implementation, you can set up your database tables, GraphQL schema, and resolvers and follow along, we would not be exploring that option as it will diverge the scope too much. We will directly use the Hygraph API you can refer to this article to set up the models and create these relationships.
Create Mutation
In our Contact Manager system when we need to create a user, we can define a createUser mutation with input fields for the user's name and email. Here's an example of using a mutation
# Request
mutationcreateCMUser($cmUser:CmUserCreateInput!){
createCmUser(data:$cmUser){
id
name
email
}
}
# Variables
{
"input":{
"name":"Jane Doe",
"email":"janedoe@hygraph.com"
}
}
This mutation creates a user with the name "John Doe" and email "johndoe@example.com" and returns the user's id, name, and email fields.
Update Mutation
In the Contact Manager system, you may want to update the information for an existing contact. This can be achieved using the update mutation. For simplicity, we will avoid passing variables but in a real-world app, always pass variables.
Delete mutations are used to delete an existing record from the database. In the Contact Manager system, we may want to delete a contact, label, or user as per needs.
To delete a record, we first need to identify the unique identifier of the record. In GraphQL, this is typically done using the ID scalar type. Once we have the ID, we can pass it as an argument to the delete mutation.
Bulk mutations allow us to modify multiple records in a single request. This significantly reduces the number of round-trips between client and server hence improving the efficiency of the application. For example, if you want to make a request wherein you want to update the company name of multiple users that have hygraph.com as a part of their email, here’s how a bulk mutation for the same would look like
# Request
mutationbulkUpdateUsers{
updateManyCmUsersConnection(
where:{email_contains:"hygraph.com"}
data:{company:"Hygraph"}
){
aggregate{
count
}
}
}
# Response
{
"data":{
"updateManyCmUsersConnection":{
"aggregate":{
"count":2
}
}
}
}
Nested Mutations
Nested mutations allow you to perform operations on related entities in one request. It allows you to insert/update data in multiple database tables in one client request only so that you do not have to make multiple trips to the server. For example in our contact manager system: We have a one-to-many relationship between our user-contact entities, if we want to create a user, two contacts for that user also connect them via the foreign key, you can do it using nested mutations.
The example below creates a new user named John Wick and also creates two contacts named Alice and Bob in Hygraph.
# Request
mutationcreateUserAndContacts{
createCmUser(
data:{
name:"John Wick",
email:"john@test.com",
cmContacts:{
create:[
{name:"Alice",phone:"789654123"},
{name:"Bob",phone:"123654798"}
]
}
}){
name
cmContacts{
name
phone
}
}
}
# Response
{
"data":{
"createCmUser":{
"name":"John Wick",
"cmContacts":[
{
"name":"Alice",
"phone":"789654123"
},
{
"name":"Bob",
"phone":"123654798"
}
]
}
}
}
Best Practices For GraphQL Mutations
Variables, Named Mutations
Just like queries, we should always use named mutations and variables in our mutations too. Named mutations enable us to debug issues by using the operation name and variables allow us to reuse the mutations by passing different values as required.
We saw how to use pre-designed mutations that were generated by Hygraph, but in case you maintain your own GraphQL server and have resolvers on top of it that power your mutations and queries, here are a few points to keep in mind while creating the design for a mutation.
A mutation should respond back with the data that it modified on the data source. This is not mandatory but it makes things much easy for the client as it doesn’t have to query again to ensure the data has changed on the data source. For instance: A mutation to update a user, should take input for updating the user, make the changes in the database and then respond with the new user object.
# Schema
typeMutation{
UpdateUser(updateUserInput:UpdateUserInput!):User
}
# Request
mutationupdateUser{
updateCmUser(
data:{name:"John",email:"john@hygraph.com"},
where:{id:"clgv03rhk08k70bocb648fydz"}
){
id
name
email
}
}
# Response
{
"data":{
"updateCmUser":{
"id":"clgv03rhk08k70bocb648fydz",
"name":"John",
"email":"john@hygraph.com"
}
}
}
A mutation should preferably take in an object instead of multiple scalar fields.
To conclude, GraphQL mutations are the entry points on a GraphQL server that provides write access to data sources. They enable modifications to be made to data sources such as creating, updating, and deleting data. Bulk mutations allow you to make changes to multiple records in a single request, nested mutations allow you to make changes in more than one database entity, and both bulk and nested mutations help improve the efficiency of the application when used correctly. Following best practices of mutations is important to ensure the right mutation design and help with debugging when needed.