Skip to content

Instantly share code, notes, and snippets.

@0-Sony
Created June 7, 2021 08:39
Show Gist options
  • Save 0-Sony/34c408a44a08b4990c9319188531e9d0 to your computer and use it in GitHub Desktop.
Save 0-Sony/34c408a44a08b4990c9319188531e9d0 to your computer and use it in GitHub Desktop.
Magento2 : Add Custom Store Configuration exposed to graphQL
<!-- etc/graphql/di.xml -->
<?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" xsi:type="array">
<item name="custom_config" xsi:type="string">mynamespace_mymodule/general/custom_config</item>
</argument>
</arguments>
</type>
</config>
# etc/schema.graphqls
type StoreConfig {
custom_config : Boolean @doc(description: "Custom Config")
}
<!-- etc/adminhtml/system.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="customtab" translate="label" sortOrder="100">
<label>Custom Tab</label>
</tab>
<section id="mynamespace_mymodule" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<tab>customtab</tab>
<label>Section Label</label>
<resource>MyNamespace_MyModule::mymodule</resource>
<group id="general" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="100">
<label>General</label>
<field id="custom_config" type="select" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="100">
<label>My Custom Config</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment