How to get the store configuration values using GraphQl in magento 2?

How to get the store config values using GraphQl in magento 2 – In This Magento blog today we are going to read about how to get the default / custom store config using GraphQl by create graphql module in magento 2 . We are creating some custom store configuration as well as default store configuration in our web sites.

You can view all my Magento 2 GraphQl articles below.

  1. What is GraphQl in Magento 2 and how to access it?
  2. How to create GraphQl schema for Magento 2 custom module with custom table?
  3. How to create a GraphQl schema by passing argument for custom magento 2 module with custom table ?
  4. How to get product attribute value, label using GraphQl in Magento 2 ?
  5. How to write GrapgQl mutation to create and integrate the contact us page functionality in Magento 2?
  6. How to filter product collection with default GraphQl products query in Magento 2?
  7. How to write custom search using GraphQl in Magento 2?

Lets Continue the article now. To get the system store config values using GraphQl. You want to follow these steps.

Assume you already have a basic module. And you already created any custom store config option in the admin panel.

1 . Define the configuration variable in the di.xml file.
2 . Create the shema.grapqls file.
3 . GraphQl query for retrieve store configuration data.

lets see step by step now.

Define the configuration variable in the di.xml file.

Want to create a di.xml file under etc/graphql directory.

In this file we want to define the item name( Ex: general_store_information_name ) as well as the field name( Ex : general/store_information/name – Section id / Group Id / Field Id).

Create the shema.grapqls file.

After setup:upgrade and cache:clean you can run the GraphQl query in the ChromeiQl. To check our query we want to set up the endpoint.It is usually coming like <magento_root_url>/graphql. Ex :- http://ayakil.local/graphql.

This is the custom system configuration admin interface which i created.

Magento system admin configuration
Custom admin configuration section.

Result will be looks like below.

In this query i have only pass few data to get the result. You can pass what ever the system configuration variables to the query and get the result. So our entire query and result looks like below.

create graphql module in magento 2
Graphql query and result in ChromieQl

Always welcome the corrections, suggestions and improvements to my blog.
Have a nice day.Enjoy coding , Learn , Experience , Teach and Help.

Praying for the quick recovery from Covid19. RIP those who are lost their lives because of this dangerous Covid19.

1 thought on “How to get the store configuration values using GraphQl in magento 2?”

Leave a Reply

Your email address will not be published. Required fields are marked *