Magento 2 How to create, update and delete custom users using GraphQL

In this blog, we will explain how to create, update and delete custom users using GraphQL query in Magento 2.

Before we start I assume you already have Magento 2 custom module with Model, Resource Model, and Collection.

It is very easy to make a GraphQL query see this step:-

Create users

1. Create schema.graphqls file in the app/code/Cynoinfotech/Users/etc folder to use the module with the following code.

2. Create CreateUser.php file in the app/code/Cynoinfotech/Users/Model/Resolver folder with the following code.

3. Create a Users.php file in the app/code/Cynoinfotech/Users/Model/Resolver/DataProvider folder with the following code.

4: Now, after executing commands

php bin/magento setup:upgrade
php bin/magento cache:clean

You can test your custom GraphQL Query in Altair GraphQL client chrome extension or you can also test in Postman Software.

Response

Delete users

1. Create schema.graphqls file in app/code/Cynoinfotech/Users/etc folder to use the module with the following code.

2. Create UsersDelete.php file in the app/code/Cynoinfotech/Users/Model/Resolver folder with the following code.

3. Create Users.php file in app/code/Cynoinfotech/Users/Model/Resolver/DataProvider folder with the following code.

You can test your custom GraphQL Query in Altair GraphQL client chrome extension or you can also test in Postman Software.

Response

We have successfully created a custom GraphQL query to insert, update and delete custom users using GraphQL in Magento 2. We hope this article helped you.

Thank You !!

Leave a Reply

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


CynoInfotech was founded in 2019, in Ahmedabad, Gujrat. CynoInfotech is a Magento module development company that grow up over this year with outsourcing clients.