How to Change GraphQL Endpoint in Magento 2
As we all know, Magento 2 supports GraphQL and it's too easy to get some information like products, categories, etc., using GraphQL. And that is the reason I have right this article because most people especially developers know how to get products, categories, etc information of any stores using the yourDomain.com/graphql endpoint. So, if you've concerned about your data security and want to change your graphql endpoint then you are at the right place. In this article, we'll learn in Magento 2 how to change the GraphQL endpoint.
Before we start I assume, you have already created a custom module. If you don't have it or don't know how to create it then check out our other article How To Create a Magento 2 Module.
Let's get started !!
Step 1: Open your module.xml file app/code/Vendor/ModuleName/etc/ and add Magento_GraphQl as a <sequence>. Check the below code for your reference.
saveCopyzoom_out_map<?xml version="1.0" ?>
<?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="Vendor_ModuleName">
<sequence>
<module name="Magento_GraphQl"/>
</sequence>
</module>
</config>
Step 2: Open/Create di.xml file app/code/Vendor/ModuleName/etc/ and add the below code under the di.xml file.
saveCopyzoom_out_map<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\App\AreaList">
<arguments>
<argument name="areas" xsi:type="array">
<item name="graphql" xsi:type="array">
<item name="frontName" xsi:type="string">devhooks_graphql</item>
</item>
</argument>
</arguments>
</type>
</config>
In above code you can see, we've use devhooks_graphql as a frontName.
Bingo!!
All set, now open Command line in folder root of magento and run the below commands.
saveCopyzoom_out_mapphp bin/magento c:c;
Now, we can access our graphql using the below URL.
saveCopyzoom_out_maphttps://yourDomain.com/devhooks_graphql
That's it.
We hope this Magento article helped you to know How to Change GraphQL Endpoint in Magento 2.
Bookmark it for your future reference. Do comment below if you have any other questions or doubts.
P.S. Do share this article with your team.
AI-Powered Recommended Articles
How to disable the graphql introspection in Magento 2.
Learn how to disable GraphQL introspection in Magento 2 to improve the security of your GraphQL endpoints.
How to Create Custom GraphQL in Magento 2
Learn how to create custom GraphQL queries in Magento 2 for enhanced API integrations.
List of GraphQL Queries and Mutations for Magento 2
Explore a comprehensive list of GraphQL queries and mutations available for Magento 2 to enhance your API usage.
Magento 2 Implement Declarative Schema in Custom Module.
A guide on implementing declarative schema in your custom Magento 2 modules to improve database management and scalability.
Magento 2 - How to add Custom Fields in Custom Option Value
Learn how to add custom fields in custom option values for Magento 2 products to enhance product customization.
How to Add Dynamic Row on Store Configuration in Magento 2
Learn how to add dynamic rows to store configuration settings in Magento 2 for flexible content management.