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 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.

<?xml version="1.0" ?> <?xml version="1.0"?> <config xmlns:xsi="" 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.

<config xmlns:xsi="" 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.


All set, now open Command line in folder root of magento and run the below commands.

php bin/magento c:c;

Now, we can access our graphql using the below URL.


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.

Review other articles maybe it'll help you too.

Recent Articles
Chrome Extension
Copyright © 2024 All rights reserved.
Ads OFF toggle_off