How the Rise of AI is Making the Travel Industry More Powerful than Before
Future of Medical Innovation: The Role of NLP in Healthcare
Hire magento developersand create Custom GraphQL in Magento 2. GraphQL is a query language for API to allow the customers to fetch the required data while the server returns only the required information. GraphQL was introduced in Magento 2.3 to replace REST and SOAP API. GraphQL is used to read data by query and write data to the server through a mutation.
Here we’ll discuss How to Create Custom GraphQL in Magento 2.
Let’s get started:
Magento Development Company create a “schema. graphics” file inside our extension below.
app\code\Vendor\Extension\etc\schema.graphqls
Now, add the below code
After that, we need to create a “CustomGraphql.php” file inside the below folder path of the extension.
app\code\Vendor\Extension\Model\Resolver\CustomGraphql.PHP
And add the below code
You need to test GraphQL Query in Altair GraphQL client chrome extension or test in Postman Software.
REST API characterizes asset data on the worker; the customer settles on the decision as it were. GraphQL permits customers to transfer a datasheet; worker activities should return a similar data.
The GraphQL worker just requires a single endpoint and precisely reacts to the data mentioned by the customer; rather than having multiple endpoints, every endpoint returns a fixed data structure as in REST.
In this model, we’ll make a simple GraphQL API inquiry to bring customer data by means of their email.
We should call our module Magenest/GraphQl. Our module should be stacked after GraphQL and Customer module so that the module.xml file would resemble this:
GraphQL queries are declared under vendor/module/etc/schema.graphqls:
Read More: Best Practices for Magento 2 Custom Theme Development
Magento development Servicesreturn data of customers with the requested email.
app/code/Magenest/GraphQl/Model/Resolver/Customer.php
For testing hire dedicated magento developers or you can check GraphQL query and response by installing a Chrome extension called “ChromeiQL”. Then, set the endpoint as “<your Magento root url>/graphql”. After that, input your GraphQL query on the left side of “ChromeiQL” interface and click on the “Set endpoint” button.
Written by Sunny Patel
Sunny Patel is a versatile IT consultant at CMARIX, a premier web app development company that provides flexible hiring models for dedicated developers. With 11+ years of experience in technology outsourcing, he spends his time understanding different business challenges and providing technology solutions to increase efficiency and effectiveness.
Hire magento developersand create Custom GraphQL in Magento 2. GraphQL is a […]