How To Get Logged-in Customer Details By Using GraphQL in Magento 2.x / Adobe Commerce 2.x

The following below steps need to follow to get logged-in Customer Details By Using GraphQL in Magento 2.x / Adobe Commerce 2.x

Step [1] – Recommendation to use below customer customer syntax

Here Using Postman

Syntax –

{customer: {Customer}}
Continue reading “How To Get Logged-in Customer Details By Using GraphQL in Magento 2.x / Adobe Commerce 2.x”

How To Get Customer Token or generateCustomerToken mutation By Using GraphQL in Magento 2.x / Adobe Commerce 2.x

The following below steps need to follow to get Customer Token or generateCustomerToken mutation By using GraphQL in Magento 2.x / Adobe Commerce 2.x

Here Using PostMan

Step [1] – Recommendation to use below customer tokens in the header of your GraphQL call

Syntax –

mutation {
  generateCustomerToken(
    email: "Enter Customer Email"
    password: "Enter Customer Password"
  ) {
    token
  }
}
Continue reading “How To Get Customer Token or generateCustomerToken mutation By Using GraphQL in Magento 2.x / Adobe Commerce 2.x”

How To Get Regions / State of Country By Using GraphQL

The following below Magento Open Source / Adobe Commerce 2.x GraphQL Query to get Regions / State of Country

Syntax::

{country(id: String) {Country}}

The following below two-letter abbreviation for the country ID (id: “US”), which returns all regions information about USA.

Continue reading “How To Get Regions / State of Country By Using GraphQL”

How To Get List of Categories By Using GraphQL in Magento 2.x

The following below Magento Open Source / Adobe Commerce 2.x GraphQL Query to get List of Categories

The category List query returns list of categories that match the criteria specified in filters

The categoryList query supports the following below filters. User can specify multiple filters in a query as per business need.

Category ID
Category name
Parent category ID
URL key
URL path

Continue reading “How To Get List of Categories By Using GraphQL in Magento 2.x”

How To Get Category By Using GraphQL in Magento 2.x

The following below Magento Open Source / Adobe Commerce 2.x GraphQL Query to get Category

category (
  id: int
): CategoryTree

The category query has been deprecated. Use the below categories query instead.

How To Get List of Categories By Using GraphQL in Magento 2.x

Continue reading “How To Get Category By Using GraphQL in Magento 2.x”

How To Get the admin authorization token For Postman in Magento / Adobe Commerce

Magento Open Source 2.x / Adobe Commerce 2.x Super Admin Credentials are self Token Authorization

The following below steps need to follow.

Step[1] – Download Postman Application & Install it

Step[2] – Once Postman Installed, do the following below things

Continue reading “How To Get the admin authorization token For Postman in Magento / Adobe Commerce”

GraphQL Interview Questions & Answers

Que-1::  What is GraphQL?
Ans-1::  GraphQL is a query language & used for APIs and includes the runtime for executing these queries.

Que-2::  When development of GraphQL has been started??
Ans-2::  GraphQL was developed internally by Facebook in 2012 and publicly released in 2015. The complete Facebook moved into GraphQL on 7 November 2018 as newly established GraphQL Foundation, hosted by the non-profit Linux Foundation. 

Que-3::  Mention list of companies using GraphQL?
Ans-3::  There are following below companies using GraphQL
            Facebook, Shopify, and Instagram, Twitter, Stack, Stackshare, 
            Microsoft, Coursera, KAVAK, Graphy, Klarna & many more as below

Que-4::  GraphQL is a Database?
Ans-4::  GraphQL is not DBMS / RDBMS, It is a Query Language used for APIs.

Que-5::  List of languages those are used to implement GraphQL Server.?
Ans-5::  The following below languages used to implement GraphQL.

JavaScript, Python, Java, PHP, Haskell, Ruby, C#, Scala, Go, Elixir, Erlang, R, and Clojure etc.

Que-6::  What is response format of GraphQL?
Ans-6::  GraphQL response as JSON format.

Que-7::  Define Overfetching in GraphQL?
Ans-7::  Overfetching is used to fetch extra data for an API request. Overfetching increases payload size..

Que-8::  Define underfetching in GraphQLL?
Ans-8::  Underfetching is used to fetch enough data. Underfetching requires multiple API calls to fetch the complete data..

Que-9::  How GraphQL helping in data loading process?
Ans-9::  GraphQL always allow the minimum number of data that is exactly required by the client, in case of the object model having a lot of fields, the client request only the required fields..

How To Get Layered Navigation Data / Search Filter Data Using GraphQL in Magento 2.x

The following below Magento 2.x GraphQL Query to get Layered Navigation Data / Search Filter Data

Syntax

{
  products(filter: { Filter Query}) {

  Filter Data
  }
}  

Below GraphQL query to get all Search Filter Data , where Category ID is 10

{
  products(filter: { category_id: { eq: "10" } }) {
    total_count
    aggregations{
      attribute_code
      label
      count
      options{
        count
        label
        value
      }
    }
  }
}

Response ::

{
  "data": {
    "products": {
      "total_count": 11,
      "aggregations": [
        {
          "attribute_code": "price",
          "label": "Price",
          "count": 5,
          "options": [
            {
              "count": 4,
              "label": "40-50",
              "value": "40_50"
            },
            {
              "count": 2,
              "label": "50-60",
              "value": "50_60"
            },
            {
              "count": 3,
              "label": "60-70",
              "value": "60_70"
            },
            {
              "count": 1,
              "label": "70-80",
              "value": "70_80"
            },
            {
              "count": 1,
              "label": "90-*",
              "value": "90_*"
            }
          ]
        },
        {
          "attribute_code": "category_id",
          "label": "Category",
          "count": 3,
          "options": [
            {
              "count": 11,
              "label": "Tops",
              "value": "12"
            },
            {
              "count": 11,
              "label": "Jackets",
              "value": "14"
            },
            {
              "count": 2,
              "label": "Eco Friendly",
              "value": "36"
            }
          ]
        },
        {
          "attribute_code": "climate",
          "label": "Climate",
          "count": 10,
          "options": [
            {
              "count": 10,
              "label": "Spring",
              "value": "207"
            },
            {
              "count": 9,
              "label": "Cool",
              "value": "203"
            },
            {
              "count": 9,
              "label": "Windy",
              "value": "209"
            },
            {
              "count": 5,
              "label": "All-Weather",
              "value": "201"
            },
            {
              "count": 5,
              "label": "Rainy",
              "value": "206"
            },
            {
              "count": 4,
              "label": "Mild",
              "value": "205"
            },
            {
              "count": 3,
              "label": "Wintry",
              "value": "210"
            },
            {
              "count": 2,
              "label": "Cold",
              "value": "202"
            },
            {
              "count": 2,
              "label": "Indoor",
              "value": "204"
            },
            {
              "count": 1,
              "label": "Warm",
              "value": "208"
            }
          ]
        },
        {
          "attribute_code": "color",
          "label": "Color",
          "count": 9,
          "options": [
            {
              "count": 6,
              "label": "Black",
              "value": "49"
            },
            {
              "count": 6,
              "label": "Red",
              "value": "58"
            },
            {
              "count": 5,
              "label": "Blue",
              "value": "50"
            },
            {
              "count": 5,
              "label": "Green",
              "value": "53"
            },
            {
              "count": 4,
              "label": "Orange",
              "value": "56"
            },
            {
              "count": 3,
              "label": "Yellow",
              "value": "60"
            },
            {
              "count": 2,
              "label": "Purple",
              "value": "57"
            },
            {
              "count": 1,
              "label": "Gray",
              "value": "52"
            },
            {
              "count": 1,
              "label": "White",
              "value": "59"
            }
          ]
        },
        {
          "attribute_code": "eco_collection",
          "label": "Eco Collection",
          "count": 1,
          "options": [
            {
              "count": 2,
              "label": "1",
              "value": "1"
            }
          ]
        },
        {
          "attribute_code": "erin_recommends",
          "label": "Erin Recommends",
          "count": 1,
          "options": [
            {
              "count": 2,
              "label": "1",
              "value": "1"
            }
          ]
        },
        {
          "attribute_code": "material",
          "label": "Material",
          "count": 10,
          "options": [
            {
              "count": 9,
              "label": "Polyester",
              "value": "38"
            },
            {
              "count": 5,
              "label": "Fleece",
              "value": "144"
            },
            {
              "count": 5,
              "label": "Nylon",
              "value": "37"
            },
            {
              "count": 2,
              "label": "Cocona® performance fabric",
              "value": "142"
            },
            {
              "count": 2,
              "label": "LumaTech™",
              "value": "147"
            },
            {
              "count": 1,
              "label": "Hemp",
              "value": "145"
            },
            {
              "count": 1,
              "label": "Lycra®",
              "value": "148"
            },
            {
              "count": 1,
              "label": "Spandex",
              "value": "150"
            },
            {
              "count": 1,
              "label": "Wool",
              "value": "158"
            },
            {
              "count": 1,
              "label": "Cotton",
              "value": "33"
            }
          ]
        },
        {
          "attribute_code": "new",
          "label": "New",
          "count": 1,
          "options": [
            {
              "count": 2,
              "label": "1",
              "value": "1"
            }
          ]
        },
        {
          "attribute_code": "pattern",
          "label": "Pattern",
          "count": 1,
          "options": [
            {
              "count": 11,
              "label": "Solid",
              "value": "196"
            }
          ]
        },
        {
          "attribute_code": "performance_fabric",
          "label": "Performance Fabric",
          "count": 1,
          "options": [
            {
              "count": 3,
              "label": "1",
              "value": "1"
            }
          ]
        },
        {
          "attribute_code": "sale",
          "label": "Sale",
          "count": 1,
          "options": [
            {
              "count": 2,
              "label": "1",
              "value": "1"
            }
          ]
        },
        {
          "attribute_code": "size",
          "label": "Size",
          "count": 5,
          "options": [
            {
              "count": 11,
              "label": "XS",
              "value": "166"
            },
            {
              "count": 11,
              "label": "S",
              "value": "167"
            },
            {
              "count": 11,
              "label": "M",
              "value": "168"
            },
            {
              "count": 11,
              "label": "L",
              "value": "169"
            },
            {
              "count": 11,
              "label": "XL",
              "value": "170"
            }
          ]
        },
        {
          "attribute_code": "style_general",
          "label": "Style General",
          "count": 12,
          "options": [
            {
              "count": 7,
              "label": "¼ zip",
              "value": "127"
            },
            {
              "count": 6,
              "label": "Lightweight",
              "value": "119"
            },
            {
              "count": 6,
              "label": "Windbreaker",
              "value": "125"
            },
            {
              "count": 5,
              "label": "Insulated",
              "value": "116"
            },
            {
              "count": 5,
              "label": "Rain Coat",
              "value": "122"
            },
            {
              "count": 5,
              "label": "Hard Shell",
              "value": "123"
            },
            {
              "count": 5,
              "label": "Soft Shell",
              "value": "124"
            },
            {
              "count": 5,
              "label": "Full Zip",
              "value": "128"
            },
            {
              "count": 3,
              "label": "Hooded",
              "value": "120"
            },
            {
              "count": 2,
              "label": "Heavy Duty",
              "value": "121"
            },
            {
              "count": 1,
              "label": "Jacket",
              "value": "117"
            },
            {
              "count": 1,
              "label": "Reversible",
              "value": "129"
            }
          ]
        }
      ]
    }

Below GraphQL query to get all Search Filter Data , where Category ID is 10 and Price range from 10 To 500 USD

{
      products(filter: { category_id: { in: "10" }, price: {from: "10" to: "500"} }) {


    total_count
    aggregations{
      attribute_code
      label
      count
      options{
        count
        label
        value
      }
    }
  }
}

Response::

{
  "data": {
    "products": {
      "total_count": 4,
      "aggregations": [
        {
          "attribute_code": "price",
          "label": "Price",
          "count": 2,
          "options": [
            {
              "count": 3,
              "label": "10-20",
              "value": "10_20"
            },
            {
              "count": 1,
              "label": "20-*",
              "value": "20_*"
            }
          ]
        },
        {
          "attribute_code": "category_id",
          "label": "Category",
          "count": 2,
          "options": [
            {
              "count": 4,
              "label": "Training",
              "value": "9"
            },
            {
              "count": 4,
              "label": "Video Download",
              "value": "10"
            }
          ]
        },
        {
          "attribute_code": "activity",
          "label": "Activity",
          "count": 5,
          "options": [
            {
              "count": 4,
              "label": "Athletic",
              "value": "16"
            },
            {
              "count": 3,
              "label": "Gym",
              "value": "11"
            },
            {
              "count": 2,
              "label": "Sports",
              "value": "17"
            },
            {
              "count": 2,
              "label": "Yoga",
              "value": "8"
            },
            {
              "count": 1,
              "label": "Outdoor",
              "value": "5"
            }
          ]
        },
        {
          "attribute_code": "format",
          "label": "Format",
          "count": 1,
          "options": [
            {
              "count": 4,
              "label": "Download",
              "value": "102"
            }
          ]
        }
      ]
    }
  }
}

How To Get Category List Data Using GraphQL in Magento 2.x

The following below Magento 2.x GraphQL Query to get Category List Data

categoryList (
   filters: CategoryFilterInput
): CategoryTree

This Query supports following below Query

  1. By Using Category ID
  2. By Using Category Name
  3. By Using URL Key
  4. By Using URL Path
  1. By Using Category ID
{
  categoryList(filters: {ids: {in: ["3", "20"]}}) {
    children_count
    children {
      id
      level
      name
      path
      url_path
      url_key
      image
      description
      children {
        id
        level
        name
        path
        url_path
        url_key
        image
        description
      }
    }
  }
}

Response::

{
  "data": {
    "categoryList": [
      {
        "children_count": "3",
        "children": [
          {
            "id": 4,
            "level": 3,
            "name": "Bags",
            "path": "1/2/3/4",
            "url_path": "gear/bags",
            "url_key": "bags",
            "image": null,
            "description": null,
            "children": []
          },
          {
            "id": 5,
            "level": 3,
            "name": "Fitness Equipment",
            "path": "1/2/3/5",
            "url_path": "gear/fitness-equipment",
            "url_key": "fitness-equipment",
            "image": null,
            "description": null,
            "children": []
          },
          {
            "id": 6,
            "level": 3,
            "name": "Watches",
            "path": "1/2/3/6",
            "url_path": "gear/watches",
            "url_key": "watches",
            "image": null,
            "description": null,
            "children": []
          }
        ]
      },
      {
        "children_count": "8",
        "children": [
          {
            "id": 22,
            "level": 3,
            "name": "Bottoms",
            "path": "1/2/20/22",
            "url_path": "women/bottoms-women",
            "url_key": "bottoms-women",
            "image": null,
            "description": null,
            "children": [
              {
                "id": 27,
                "level": 4,
                "name": "Pants",
                "path": "1/2/20/22/27",
                "url_path": "women/bottoms-women/pants-women",
                "url_key": "pants-women",
                "image": null,
                "description": null
              },
              {
                "id": 28,
                "level": 4,
                "name": "Shorts",
                "path": "1/2/20/22/28",
                "url_path": "women/bottoms-women/shorts-women",
                "url_key": "shorts-women",
                "image": null,
                "description": null
              }
            ]
          },
          {
            "id": 21,
            "level": 3,
            "name": "Tops",
            "path": "1/2/20/21",
            "url_path": "women/tops-women",
            "url_key": "tops-women",
            "image": null,
            "description": null,
            "children": [
              {
                "id": 23,
                "level": 4,
                "name": "Jackets",
                "path": "1/2/20/21/23",
                "url_path": "women/tops-women/jackets-women",
                "url_key": "jackets-women",
                "image": null,
                "description": null
              },
              {
                "id": 24,
                "level": 4,
                "name": "Hoodies & Sweatshirts",
                "path": "1/2/20/21/24",
                "url_path": "women/tops-women/hoodies-and-sweatshirts-women",
                "url_key": "hoodies-and-sweatshirts-women",
                "image": null,
                "description": null
              },
              {
                "id": 25,
                "level": 4,
                "name": "Tees",
                "path": "1/2/20/21/25",
                "url_path": "women/tops-women/tees-women",
                "url_key": "tees-women",
                "image": null,
                "description": null
              },
              {
                "id": 26,
                "level": 4,
                "name": "Bras & Tanks",
                "path": "1/2/20/21/26",
                "url_path": "women/tops-women/tanks-women",
                "url_key": "tanks-women",
                "image": null,
                "description": null
              }
            ]
          }
        ]
      }
    ]

[2] – By Using Category Name

{
	categoryList(filters: { name: { match: "Gear" } }) {
	products {
	total_count
		page_info {
		current_page
		page_size
		}
	 }
	children_count
		children {
		id
		level
		name
		path
			children {
			id
			level
			name
			path
				children {
				id
				level
				name
				path
				children {
				id
				level
				name
				path
				}
				}
			}
		}
	}
}

Response ::

{
  "data": {
    "categoryList": [
      {
        "products": {
          "total_count": 34,
          "page_info": {
            "current_page": 1,
            "page_size": 20
          }
        },
        "children_count": "3",
        "children": [
          {
            "id": 4,
            "level": 3,
            "name": "Bags",
            "path": "1/2/3/4",
            "children": []
          },
          {
            "id": 5,
            "level": 3,
            "name": "Fitness Equipment",
            "path": "1/2/3/5",
            "children": []
          },
          {
            "id": 6,
            "level": 3,
            "name": "Watches",
            "path": "1/2/3/6",
            "children": []
          }
        ]
      }
    ]
  }
}

By Using Root Category 2

{
	category(id: 2) {
	products {
	total_count
		page_info {
		current_page
		page_size
		}
	 }
	children_count
		children {
		id
		level
		name
		path
			children {
			id
			level
			name
			path
				children {
				id
				level
				name
				path
				children {
				id
				level
				name
				path
				}
				}
			}
		}
	}
}

Above Query Response :: All List of Categories & Sub Categories Data

{
  "data": {
    "category": {
      "products": {
        "total_count": 187,
        "page_info": {
          "current_page": 1,
          "page_size": 20
        }
      },
      "children_count": "38",
      "children": [
        {
          "id": 20,
          "level": 2,
          "name": "Women",
          "path": "1/2/20",
          "children": [
            {
              "id": 22,
              "level": 3,
              "name": "Bottoms",
              "path": "1/2/20/22",
              "children": [
                {
                  "id": 27,
                  "level": 4,
                  "name": "Pants",
                  "path": "1/2/20/22/27",
                  "children": []
                },
                {
                  "id": 28,
                  "level": 4,
                  "name": "Shorts",
                  "path": "1/2/20/22/28",
                  "children": []
                }
              ]
            },
            {
              "id": 21,
              "level": 3,
              "name": "Tops",
              "path": "1/2/20/21",
              "children": [
                {
                  "id": 23,
                  "level": 4,
                  "name": "Jackets",
                  "path": "1/2/20/21/23",
                  "children": []
                },
                {
                  "id": 24,
                  "level": 4,
                  "name": "Hoodies & Sweatshirts",
                  "path": "1/2/20/21/24",
                  "children": []
                },
                {
                  "id": 25,
                  "level": 4,
                  "name": "Tees",
                  "path": "1/2/20/21/25",
                  "children": []
                },
                {
                  "id": 26,
                  "level": 4,
                  "name": "Bras & Tanks",
                  "path": "1/2/20/21/26",
                  "children": []
                }
              ]
            }
          ]
        },
        {
          "id": 11,
          "level": 2,
          "name": "Men",
          "path": "1/2/11",
          "children": [
            {
              "id": 12,
              "level": 3,
              "name": "Tops",
              "path": "1/2/11/12",
              "children": [
                {
                  "id": 14,
                  "level": 4,
                  "name": "Jackets",
                  "path": "1/2/11/12/14",
                  "children": []
                },
                {
                  "id": 15,
                  "level": 4,
                  "name": "Hoodies & Sweatshirts",
                  "path": "1/2/11/12/15",
                  "children": []
                },
                {
                  "id": 16,
                  "level": 4,
                  "name": "Tees",
                  "path": "1/2/11/12/16",
                  "children": []
                },
                {
                  "id": 17,
                  "level": 4,
                  "name": "Tanks",
                  "path": "1/2/11/12/17",
                  "children": []
                }
              ]
            },
            {
              "id": 13,
              "level": 3,
              "name": "Bottoms",
              "path": "1/2/11/13",
              "children": [
                {
                  "id": 18,
                  "level": 4,
                  "name": "Pants",
                  "path": "1/2/11/13/18",
                  "children": []
                },
                {
                  "id": 19,
                  "level": 4,
                  "name": "Shorts",
                  "path": "1/2/11/13/19",
                  "children": []
                }
              ]
            }
          ]
        },
        {
          "id": 9,
          "level": 2,
          "name": "Training",
          "path": "1/2/9",
          "children": [
            {
              "id": 10,
              "level": 3,
              "name": "Video Download",
              "path": "1/2/9/10",
              "children": []
            }
          ]
        },
        {
          "id": 3,
          "level": 2,
          "name": "Gear",
          "path": "1/2/3",
          "children": [
            {
              "id": 4,
              "level": 3,
              "name": "Bags",
              "path": "1/2/3/4",
              "children": []
            },
            {
              "id": 5,
              "level": 3,
              "name": "Fitness Equipment",
              "path": "1/2/3/5",
              "children": []
            },
            {
              "id": 6,
              "level": 3,
              "name": "Watches",
              "path": "1/2/3/6",
              "children": []
            }
          ]
        },
        {
          "id": 38,
          "level": 2,
          "name": "What's New",
          "path": "1/2/38",
          "children": []
        },
        {
          "id": 37,
          "level": 2,
          "name": "Sale",
          "path": "1/2/37",
          "children": []
        }
      ]
    }
  }
}