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_map
php bin/magento c:c;

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

saveCopyzoom_out_map
https://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.

Review other articles maybe it'll help you too.




Search
Recent Articles
Tags
Newsletter
Copyright © 2022 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off