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

CynoInfotech

CynoInfotech was founded in 2019, in Ahmedabad, Gujrat. we have a trusted Web Development and Design Company that helps businesses in streamlining their operations through Magento 2 Extension and advanced modern technology solutions.

Let’s connect