Magento 2 GraphQL Cheatsheet 2025
Magento 2 has embraced an API-first approach with robust GraphQL support, making it a go-to choice for headless commerce and modern frontend frameworks like React, Vue, and PWA Studio. This Magento 2 GraphQL Cheatsheet 2025 is your go-to hub that links all my hands-on GraphQL tutorials, organized section-wise with real-life examples and ready-to-use code.
Whether you’re a frontend developer building a custom React UI or a Magento backend dev testing APIs with Altair or GraphiQL, this post will fast-track your development.
Customer
Everything you need to manage customers — registration, authentication, and email validation.
🔹 Create Customer Account Using Magento 2 GraphQL
Learn how to register a new customer using the createCustomerV2 mutation.
🔹 Generate Customer Token Using Magento 2 GraphQL
Use the generateCustomerToken mutation to authenticate and fetch a JWT token.
🔹 Check Email Availability in Magento 2 Using GraphQL
Verify if a customer email is already registered using the isEmailAvailable query.
Company (Adobe Commerce B2B)
For B2B stores on Adobe Commerce — validate company admin/user emails.
🔹 Check Company, Customer, and Admin Email Availability
Covers isCompanyEmailAvailable query to validate:
- Company Admin Emails
- Company User Emails
- Customer Emails
Orders
(Coming Soon)
Planned tutorials to include:
- Fetch customer order history
- View individual order details
- Cancel orders via GraphQL
Wishlist
(Coming Soon)
Planned tutorials to include:
- Add product to wishlist
- Get wishlist items
- Remove wishlist item
Cart & Checkout
(Coming Soon)
Planned tutorials:
- Add product to cart (
addSimpleProductsToCart) - Update item quantity
- Remove cart items
- Set shipping and billing address
- Fetch available shipping/payment methods
- Place order (
placeOrder)
Authentication & Tokens
This overlaps with the Customer section but is critical enough to highlight separately.
🔹 Generate Customer Token Using GraphQL
Get secure access tokens to authorize customer actions in the storefront.
Store Configuration / Metadata
(Coming Soon)
Planned GraphQL tutorials:
- Fetch store configurations
- Get currency, locale, store view details
- Load CMS page or blocks via GraphQL
This blog will evolve. Bookmark it or subscribe to my newsletter for updates as I publish more Magento 2 GraphQL content.
How to Check Email Availability for Company, User & Admin in Magento 2 B2B using GraphQL
In Magento 2 B2B (Business-to-Business) environments, ensuring email uniqueness is essential when registering a company, assigning company users, or creating admin roles. Magento provides GraphQL queries to validate email availability for each use case.
In this tutorial, we’ll explore the following GraphQL queries:
isCompanyEmailAvailableisCompanyUserEmailAvailableisCompanyAdminEmailAvailable
All queries require a valid customer token and return a boolean value indicating whether the given email is available for the requested action.
Prerequisite: Generate Customer Token
Before using any of these queries, you need to generate a customer token via GraphQL:
mutation {
generateCustomerToken(
email: "johndoe@example.com"
password: "CustomerPassword123"
) {
token
}
}
Use this token as the Authorization header for the upcoming queries:
Authorization: Bearer <customer-token>Check Email Availability for Company Registration
Query: isCompanyEmailAvailable
This query checks if the provided email can be used to register a new company. It returns false if the email already belongs to an existing company or customer.
Syntax
query{
isCompanyEmailAvailable(email: "roni_cost@example.com"){
is_email_available
}
}Result
{
"data": {
"isCompanyEmailAvailable": {
"is_email_available": true
}
}
}
Check Email Availability for Company User
Query: isCompanyUserEmailAvailable
Use this query to check whether an email can be used to add a new user to a company. It returns false if the email already belongs to a customer or company admin.
Syntax
{
isCompanyUserEmailAvailable(email: "roni_cost@example.com") {
is_email_available
}
}
Output
{
"data": {
"isCompanyUserEmailAvailable": {
"is_email_available": false
}
}
}
Check Email Availability for Company Admin
Query: isCompanyAdminEmailAvailable
This query checks if the given email is available to be used as a Company Administrator. Returns false if it already belongs to a customer or another company admin.
Syntax
query {
isCompanyAdminEmailAvailable(email: "roni_cost@example.com") {
is_email_available
}
}
Output
{
"data": {
"isCompanyAdminEmailAvailable": {
"is_email_available": false
}
}
}
With these GraphQL queries, validating email availability for different roles in Magento 2 B2B becomes straightforward and efficient. Whether you’re registering a company, assigning users, or setting up admins — you can ensure data integrity and avoid conflicts right from the frontend.
You may also like,
How to Create a Customer Account Using Magento 2 GraphQL
How to Check Email Availability in Magento 2 Using GraphQL (2.4.7+)
How to Generate a Customer Token Using Magento 2 GraphQL
Resources
How to Check Email Availability in Magento 2 Using GraphQL (2.4.7+)
In Magento 2, especially when building custom frontends with PWA Studio, Vue Storefront, or any headless frontend using GraphQL, it's important to know whether a customer's email is already registered before account creation.
Magento provides a simple query for this: isEmailAvailable.
But starting from Magento 2.4.7, its behavior has slightly changed and may lead to confusion if you're unaware of the config setting involved. Let’s break it down.
What is isEmailAvailable?
The isEmailAvailable GraphQL query allows you to verify if an email address is already associated with an existing customer account.
- Returns
trueif the email is available to create a new account. - Returns
falseif the email is already in use.
But in Magento 2.4.7 and later, the behavior is modified for privacy and security reasons.
Important Change in Magento 2.4.7
By default, Magento 2.4.7 always returns:
{
"data": {
"isEmailAvailable": {
"is_email_available": true
}
}
}Even for already registered emails.
Why?
To prevent exposing customer data (like whether someone’s email exists on your store), Magento now hides that information unless you explicitly allow it.
How to Enable Real Email Availability Check?
To restore the actual checking behavior:
- Go to your Magento Admin
- Navigate to:
Stores > Configuration > Sales > Checkout - Set Enable Guest Checkout Login to Yes
⚠️ Warning: Enabling this will reveal email existence status to unauthenticated users, which could lead to privacy concerns.
GraphQL Syntax
{
isEmailAvailable(email: "customer@example.com") {
is_email_available
}
}
Parameters
- email (String!): The email you want to check.
Example Usage
Request
{
isEmailAvailable(email: "hello@jigarkarangiya.com") {
is_email_available
}
}
Response
{
"data": {
"isEmailAvailable": {
"is_email_available": true
}
}
}
- true → Email is available
- false → Email is already in use
When to Use This?
In custom signup flows to give users instant feedback
During customer registration on headless frontends
For progressive web apps (PWAs)
Related Resources
The isEmailAvailable GraphQL query is a useful tool in building smarter and user-friendly registration forms for your Magento 2 store. But with Magento 2.4.7, don’t forget the behavior change — it now always returns true unless you configure it otherwise.
You may also like,
How to Generate a Customer Token Using Magento 2 GraphQL
How to Create a Customer Account Using Magento 2 GraphQL
How to Create a Customer Account Using Magento 2 GraphQL
Creating a customer account is one of the most essential operations in any eCommerce store. Magento 2 supports this via REST and GraphQL APIs. In this blog, we'll explore how to create a customer account using GraphQL in Magento 2 with examples, query structure, and best practices.
Whether you’re a developer integrating a mobile app or building a headless frontend with React or Vue, this guide will help you get started.
Why Use GraphQL for Customer Operations?
Magento 2 introduced full GraphQL support for storefront operations, which allows frontend developers to:
- Request only the data needed
- Improve performance with fewer API calls
- Simplify integration for mobile apps and PWA Studio
Creating a customer account via GraphQL is clean, efficient, and fast.
Prerequisites
Before we dive into the query, make sure:
- Your Magento 2 store is version 2.3.3 or above (GraphQL stable)
- GraphQL module is enabled
- A GraphQL client like Altair, Postman, or Magento PWA Studio is ready
- Magento base URL is accessible, typically like:
https://yourstore.com/graphqlGraphQL Mutation to Create a Customer Account
Magento provides a mutation called createCustomer to register new accounts.
mutation {
createCustomer(
input: {
firstname: "John"
lastname: "Doe"
email: "john.doe@example.com"
password: "StrongPassword123"
}
) {
customer {
id
firstname
lastname
email
}
}
}The field Mutation.createCustomer is deprecated. Use `createCustomerV2` instead.
In this blog, We will use createCustomerV2 mutation.
Request
mutation {
createCustomerV2(
input: {
firstname: "Jigar"
lastname: "Karangiya"
email: "jigarkarangiyablogs@gmail.com"
password: "b0bl0bl@w"
is_subscribed: true
}
) {
customer {
firstname
lastname
email
is_subscribed
}
}
}
Response
{
"data": {
"createCustomer": {
"customer": {
"firstname": "Jigar",
"lastname": "Karangiya",
"email": "jigarkarangiyablogs@gmail.com",
"is_subscribed": true,
}
}
}
}
As of version 2.4.7, you can use the custom_attributes field to define an array of custom attributes to apply to the customer.
Create customer account with custom attributes
Request
mutation {
createCustomerV2(
input: {
firstname: "Jigar"
lastname: "Karangiya"
email: "jigar.karangiya@test.com"
password: "sjjsjs@444js#"
is_subscribed: true
custom_attributes: [
{
attribute_code: "alternative_email"
value: "jigar.karangiya@2ndemail.com"
},
{
attribute_code: "certificates"
value: "992,995"
selected_options: [
{
uid: "Adobe Commerce - Certified Professional Developer"
value: "992"
},
{
uid: "Adobe Commerce - Certified Expert Developer"
value: "995"
}
]
}
]
}
) {
customer {
firstname
lastname
email
is_subscribed
custom_attributes {
code
... on AttributeValue {
value
}
... on AttributeSelectedOptions {
selected_options {
label
value
}
}
}
}
}
}
Response
{
"data": {
"createCustomer": {
"customer": {
"firstname": "Jigar",
"lastname": "Karangiya",
"email": "jigar.karangiya@test.com",
"is_subscribed": true,
"custom_attributes": [
{
"code": "alternative_email",
"value": "jigar.karangiya@2ndemail.com"
},
{
"code": "certificates",
"selected_options": [
{
"label": "Adobe Commerce - Certified Professional Developer",
"value": "992"
},
{
"label": "Adobe Commerce - Certified Expert Developer",
"value": "995"
}
]
}
]
}
}
}
}
Input attributes
You can use the following attributes as input for the createCustomerV2 mutation.
| Field Name | Description |
|---|---|
allow_remote_shopping_assistance - Boolean | Indicates whether the customer has enabled remote shopping assistance. |
custom_attributes - [AttributeValueInput] | The customer's custom attributes. |
date_of_birth - String | The customer's date of birth. |
dob - String | |
email - String! | The customer's email address. |
firstname - String! | The customer's first name. |
gender - Int | The customer's gender (Male - 1, Female - 2). |
is_subscribed - Boolean | Indicates whether the customer is subscribed to the company's newsletter. |
lastname - String! | The customer's family name. |
middlename - String | The customer's middle name. |
password - String | The customer's password. |
prefix - String | An honorific, such as Dr., Mr., or Mrs. |
suffix - String | A value such as Sr., Jr., or III. |
taxvat - String | The customer's Tax/VAT number (for corporate customers). |
Common Response Errors
| Error | Description |
|---|---|
A customer with the same email address already exists in an associated website. | The email provided in the input.email argument belongs to an existing customer. |
"Email" is not a valid email address. | The value provided in the input.email argument has an invalid format. |
Field CustomerInput.email of required type String! was not provided | The input.email argument was omitted. |
Field "xxx" is not defined by type CustomerInput. | The input.xxx argument is undefined. |
Required parameters are missing: First Name | The input.firstname argument was omitted or contains an empty value. |
Creating a customer account via Magento 2 GraphQL is straightforward, clean, and ideal for headless and modern frontend setups. With the power of GraphQL, developers can craft highly optimized experiences while keeping control of what data is sent or received.
You may also like,
How to Generate a Customer Token Using Magento 2 GraphQL
How to Generate a Customer Token Using Magento 2 GraphQL
If you’re building a headless storefront, mobile app, or just exploring Magento 2’s modern capabilities, GraphQL authentication is a must-know topic. In this tutorial, I’ll show you how to generate a customer access token using GraphQL in Magento 2.
This token is essential for making authenticated requests on behalf of the logged-in customer (like fetching their orders, addresses, wishlist, etc.).
Prerequisites
Before you start, make sure:
- Magento 2.3 or higher is installed (GraphQL is supported natively from 2.3+)
- GraphQL is enabled (default in Magento)
- You have a customer account created in Magento
- A tool to test GraphQL requests like:
- Altair GraphQL Client
- Postman
- Magento’s built-in
/graphqlendpoint
Why Do You Need a Customer Token?
Magento uses OAuth-based access control for APIs. Instead of using session-based logins, GraphQL returns an access token when the customer logs in via their credentials. This token can be sent with future requests for secure access to customer-specific resources.
GraphQL Mutation for Generate Customer Token
To generate a token, use the generateCustomerToken mutation.
Mutation Syntax
mutation {
generateCustomerToken(
email: String!
password: String!
) {
token
}
}
Replace the email and password with your registered customer's credentials.
Example (Request Body)
mutation {
generateCustomerToken(
email: "roni_cost@example.com"
password: "roni_cost3@example.com"
) {
token
}
}
Response (Output)
{
"data": {
"generateCustomerToken": {
"token": "eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjEsInV0eXBpZCI6MywiaWF0IjoxNzQ5Mzk3MjQ4LCJleHAiOjE3NDk0MDA4NDh9.RP05hYN_0YiGtrdXkF88MP0USc4qA3hSm0p-Zz4ZveQ"
}
}
}The returned token is what you’ll use to make authenticated API calls as the customer.

How to Use the Token?
You can add the token as a bearer token in the Authorization header for your future GraphQL queries.
Example Header
Authorization: Bearer 6o3y6xyksoi2av5fejhe7z24ljv7u3z1

Example Authenticated Query (Fetch Customer Info)
query {
customer {
firstname
lastname
email
}
}Sample Output
{
"data": {
"customer": {
"firstname": "Veronica",
"lastname": "Costello",
"email": "roni_cost@example.com"
}
}
}
Magento 2’s GraphQL customer token is a powerful tool for secure and modern customer authentication. Whether you're building an app, SPA, or just exploring APIs — this mutation is your gateway to personalized commerce.
If you're new to GraphQL in Magento 2, this is one of the first steps you should learn. Master it and you’re well on your way to building powerful frontend experiences!
We will see other useful Magento 2 Default GraphQL endpoints in upcoming blogs.
Frequently Asked Questions
A customer token in Magento 2 is a secure JSON Web Token (JWT) generated after a customer successfully logs in via GraphQL. This token is used to authenticate the customer for subsequent API requests.
GraphQL provides a modern and flexible API, allowing you to fetch exactly the data you need. It's ideal for headless storefronts, SPAs, and mobile apps that require efficient and secure authentication.
Use the generateCustomerToken mutation with the customer's email and password.
Send your GraphQL request to the /graphql endpoint of your Magento 2 store, e.g.:https://your-magento-site.com/graphql
By default, a customer token is valid for 1 hour. This duration can be configured from the Magento admin panel.
Magento 2 does not provide a refresh token mechanism for customer tokens out-of-the-box. After expiration, you must re-authenticate (login again) to obtain a new token.
Yes, as long as you use HTTPS to encrypt communication and securely store tokens on the client side, customer tokens are safe for production use.
For customer-specific queries or mutations, include the token in the Authorization header:Authorization: Bearer <customer-token>
No, customer tokens are only valid for customer-level GraphQL operations. For admin API access, use an admin token.
Yes, you can configure the token lifetime in the Magento admin:
Go to Stores > Settings > Configuration > Services > OAuth > Access Token Expiration.




