In this blog post, we will explain how to fetch the data from store configuration value of our custom module by using graphql. You ned to follow these steps.
Contents
hide
Step 1. First Create the registration.php file
Code:
1 2 3 4 5 6 7 8 9 10 11 |
<?php /** * @category Webiators * @package Webiators_CustomChangesGraphQl * @author Webiators Team * @copyright Copyright (c) Webiators Technologies Private Limited. ( https://store.webiators.com/ ). */ */ use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Webiators_CustomChangesGraphQl', __DIR__); |
Step 2. First Create the module.xml file
Code:
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Webiators_CustomChangesGraphQl" setup_version="1.0.0"/> <sequence> <module name="Magento_GraphQl"/> <module name="Magento_Backend"/> </sequence> </config> |
Step 3. First Create the di.xml file
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" ?> <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="custom_changes_general_enable" xsi:type="string">custom_changes/general/enable</item> <item name="custom_changes_general_enable_on_product_page" xsi:type="string">custom_changes/general/enable_on_product_page</item> <item name="custom_changes_general_enable_on_list_page" xsi:type="string">custom_changes/general/enable_on_list_page</item> <item name="custom_changes_general_product_button_label" xsi:type="string">custom_changes/general/product_button_label</item> </argument> </arguments> </type> </config> |
Step 4. First Create the schema.graphqls file
Code:
1 2 3 4 5 6 7 |
type StoreConfig { custom_changes_general_enable : String @doc(description: "To check module enable or disable") , custom_changes_general_enable_on_product_page: String @doc(description: "To check module enable or disable on product page") , custom_changes_general_enable_on_list_page : String @doc(description: "To check module enable or disable on list page") , custom_changes_general_product_button_label: String @doc(description: "To fetch product button label") } |
Step 5. Now, execute the following commands
1 2 3 4 5 6 7 |
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f en_US php bin/magento cache:flush php bin/magento cache:clean php bin/magento indexer:reindex |
Step 6. Now, you need to pass the query required data in the Request Body.
1 2 3 4 5 6 7 8 9 10 |
{ storeConfig{ custom_changes_general_enable custom_changes_general_enable_on_product_page custom_changes_general_enable_on_list_page custom_changes_general_product_button_label } } |
Thank You!
Hit 5 Stars if you find this post helpful
0 (based on 0 Reviews)