Friday, 20 December 2019

about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento implements GraphQL to provide an alternative to REST and SOAP web APIs for frontend development.

GraphQL allows you to define the structure of the data that you need, and the server returns only the data you request. Each GraphQL-capable module contains a declarative schema that defines the syntax for queries that the module supports, as well as the attributes that can be returned. If you run a REST call such as GET /V1/products/:sku on a simple product, the system might fetch more than 100 lines of data. If all you need is the current price, the call has returned significantly more information than you need. With GraphQL, a query against the same SKU could return just the price.

You can read more details about GraphQL here.

You can check out the GraphQL tutorial here.

Let me share some useful links regarding Magento 2 GraphQL a new feature released.

=> Exaple 1

=> Example 2


Magento 2 How to add custom attribute to customer address and how to insert value in that attribute?

Magento 2 How to add a custom attribute to customer address and how to insert value in that attribute? To check the answer to the above question please click here


You can also check more Magento related Question/Answers here

Magento 2 How to duplicate the category with same structure?

I want to duplicate the category with the same structure and data.

How to duplicate child categories here? It is working correctly for a single category.

In my controller file, I have the parent category id and category id which needs to duplicate. Now how can I create duplication of a category?

Please check my code is as below:

    class DuplicateCategory extends \Magento\Backend\App\Action {
    protected $_categoryFactory;
    public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
    parent::__construct($context);
    $this->_categoryFactory = $categoryFactory;
    }

    $parentCategoryObj = $this->_categoryFactory->create()->load(2);
    $duplicateCategoryObj = $this->_categoryFactory->create()->load(8);
    $catagoryObject = $this->_categoryFactory->create();

    $categoryName = $duplicateCategoryObj->getName();
    $categoryUrlKey = strtolower($this->getCategoryUrlKey($categoryName));

    $catagoryObject->setPath($parentCategoryObj->getPath())
    ->setParentId($parentCategory)
    ->setName($duplicateCategoryObj->getName())
    ->setUrlKey($categoryUrlKey)
    ->setStoreId($storeId)
    ->setIsActive(true);
    $catagoryObject->save();
    }
You can also check more Magento related Question/Answers here

about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento impleme...