Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Last active June 27, 2022 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexander-Pop/9b816824f7290e56e5e38f415cbf5736 to your computer and use it in GitHub Desktop.
Save Alexander-Pop/9b816824f7290e56e5e38f415cbf5736 to your computer and use it in GitHub Desktop.
Magento 2 : expose Custom Store Configuration to graphQL #magento2 #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_foo_config" xsi:type="string">mynamespace_mymodule/general/custom_foo_config</item>
</argument>
</arguments>
</type>
</config>
# etc/schema.graphqls
type StoreConfig {
custom_foo_config : Boolean @doc(description: "Custom Important 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_foo_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