Magento, Magento 2

How to Get Configuration Value using GraphQL in Magento 2

How to Get Configuration Value using GraphQL in Magento 2

In this tutorial, Today I will explain to how to get store configuration value using GraphQL in Magento 2. After Magento 2.3.x, GraphQL is best feature added in Magento 2. Now, Some functionality by default provided in Magento 2 GraphQL. But, some functionalities still not available in GraphQL.

However, If you want to get some store configuration value using GraphQL then, what should we need to do? So, Let’s follow the below steps :

You may also like this :

Steps to Get Configuration Value using GraphQL in Magento 2

1) First of all, Let’s assume that you have created simple module. Now, you need to create schema.graphqls at app/code/RH/CustomGraphQl/etc/ and paste the below code for add field which you want to get config value :

# Copyright © Magento, Inc. All rights reserved.
# Created By : Rohan Hapani

type StoreConfig {
    web_unsecure_base_url : String  @doc(description: "Web Unsecure Base URL"),
    catalog_review_allow_guest : String  @doc(description: "Check Catalog Review Allow to Guest")
}

2) After that, you need to create di.xml file at app/code/RH/CustomGraphQl/etc/graphql/ and paste the below code add store config item which you want to get field’s value :

<?xml version="1.0" ?>
<!--
/**
 * Created By : Rohan Hapani
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
        <arguments>
            <argument name="extendedConfigData">
                <item name="web_unsecure_base_url" xsi:type="string">web/unsecure/base_url</item>
                <item name="catalog_review_allow_guest" xsi:type="string">catalog/review/allow_guest</item>
            </argument>
        </arguments>
    </type>
</config>

Here, you need to add section/group/field as item value inside argument and also need to set item name. You can set your field value which you want to get configuration value.

Now, You need to upgrade and deploy your module.

php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:c

In Last, check query output by installing chrome extension ChromeiQL or Postman (GraphQL supported version).

Execute URL : http://127.0.0.1/m235/graphql

Where Base URL : http://127.0.0.1/m235/ and End Point : graphql

Request Body :

{
    storeConfig {
        web_unsecure_base_url
        catalog_review_allow_guest
    }
}

Response :

{
  "data": {
    "storeConfig": {
      "web_unsecure_base_url": "http://127.0.0.1/m235/",
      "catalog_review_allow_guest": "1"
    }
  }
}

Output :

 

System Config GraphQL Magento 2

That’s it !!!

I hope this blog is easy to understand about how to get store configuration value using GraphQL in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.

Stay Safe and Stay Connected !!

Tagged , ,