<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Graphql Archives - Kpyxal Solutions LLP</title>
	<atom:link href="https://www.kpyxal.com/category/magento/graphql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kpyxal.com/category/magento/graphql/</link>
	<description></description>
	<lastBuildDate>Fri, 06 Sep 2024 13:44:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://www.kpyxal.com/wp-content/uploads/2024/07/cropped-48x48_logo-32x32.webp</url>
	<title>Graphql Archives - Kpyxal Solutions LLP</title>
	<link>https://www.kpyxal.com/category/magento/graphql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mutation in GRAPHQL</title>
		<link>https://www.kpyxal.com/magento/mutation-in-graphql/</link>
					<comments>https://www.kpyxal.com/magento/mutation-in-graphql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 20 Feb 2023 16:04:27 +0000</pubDate>
				<category><![CDATA[Graphql]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[expert exam with cloud addon AD0-E716]]></category>
		<category><![CDATA[graphql mutation example]]></category>
		<category><![CDATA[headless with graphql]]></category>
		<category><![CDATA[KPYXAL]]></category>
		<category><![CDATA[Kpyxal Solutions LLP]]></category>
		<category><![CDATA[magento certification]]></category>
		<category><![CDATA[magento2 caching]]></category>
		<category><![CDATA[magento2 graphql mutation]]></category>
		<guid isPermaLink="false">https://www.kpyxal.com/?p=92</guid>

					<description><![CDATA[<p>In the world of GraphQL, queries and mutations play distinct but complementary roles.Specifically, While GraphQL queries are designed to perform read operations, mutations handle the task of modifying data. Essentially, a mutation allows you to create, update, or delete objects and fields, functioning similarly to POST, PUT, and DELETE requests in REST terminology. Moreover, Understanding [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.kpyxal.com/magento/mutation-in-graphql/">Mutation in GRAPHQL</a> appeared first on <a rel="nofollow" href="https://www.kpyxal.com">Kpyxal Solutions LLP</a>.</p>
]]></description>
										<content:encoded><![CDATA[<figure class="wp-block-post-featured-image"><img loading="lazy" width="500" height="500" src="https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Mutation in GRAPHQL" decoding="async" srcset="https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL.png 500w, https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL-300x300.png 300w, https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL-150x150.png 150w, https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL-370x370.png 370w, https://www.kpyxal.com/wp-content/uploads/2023/02/Mutation-in-GRAPHQL-60x60.png 60w" sizes="(max-width: 500px) 100vw, 500px" /></figure>


<p>In the world of GraphQL, queries and mutations play distinct but complementary roles.Specifically,  While GraphQL queries are designed to perform read operations, mutations handle the task of modifying data. Essentially, a mutation allows you to create, update, or delete objects and fields, functioning similarly to POST, PUT, and DELETE requests in REST terminology. Moreover, Understanding the structure and function of mutations is crucial for effective data manipulation and application management. Therefore, In this context, let&#8217;s delve into the components that make up a Mutation in GRAPHQL and see how they contribute to its functionality.</p>



<h3 id="structure-of-a-mutation">Structure of a mutation<a href="https://developer.adobe.com/commerce/webapi/graphql/usage/#structure-of-a-mutation"></a></h3>



<p>Mutations consist of several key elements:</p>



<ul>
<li>First, you need the keyword &#8216;mutation.</li>



<li>An operation name for your local implementation. Consequently, this name is required if you include variables. On the other hand, it is optional.</li>



<li>The mutation name</li>



<li>The input object or attributes.In particular, Most mutations require an input object that contains data or individual attributes for the application server to process. However, on the other hand, some mutations, such as createEmptyCart, do not require an input object. In this particular case, therefore, the authorization token passed with the request provides the needed context.</li>



<li>The output object, which specifies which data the mutation returns.</li>
</ul>



<h2>Example of mutation graphql</h2>



<p>Here in this example, we are, indeed, adding data to the database using a GraphQL mutation.</p>



<p><strong>Step 1 :-</strong>&nbsp;You Create&nbsp;<strong><code>registration.php</code></strong>&nbsp;file</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="registration.php" data-lang="PHP"><code>&lt;?php
/**
 * @author KPYXAL
 * @copyright Copyright (c) 2023
 * @package Kpyxal_MutationGraphql
 */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    &#39;Kpyxal_MutationGraphql&#39;,
    __DIR__
);</code></pre></div>



<p><strong>Step 2 :-</strong>&nbsp;create&nbsp;<strong><code>etc/module.xml</code></strong>&nbsp;file</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="module.xml" data-lang="PHP"><code>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!--
/**
 * @author KPYXAL
 * @copyright Copyright (c) 2023
 * @package Kpyxal_MutationGraphql
 */
--&gt;

&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;config xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module/etc/module.xsd&quot;&gt;
    &lt;module name=&quot;Kpyxal_MutationGraphql&quot; setup_version=&quot;2.0.0&quot;&gt;
        &lt;sequence&gt;
            &lt;module name=&quot;Magento_Backend&quot;/&gt;
            &lt;module name=&quot;Magento_GraphQl&quot;/&gt;
        &lt;/sequence&gt;
    &lt;/module&gt;
&lt;/config&gt;</code></pre></div>



<p><strong>Step 3 :-</strong>&nbsp;GraphQL queries are declared under&nbsp;<strong><code>etc/schema.graphqls</code></strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="schema.graphqls" data-lang="PHP"><code>type Mutation {
    dataFormSubmit(input: FormInput!): FormOutput @resolver(class: &quot;\\Kpyxal\\MutationGraphql\\Model\\Resolver\\FormDataSave&quot;) @doc(description:&quot;Contact us form&quot;)
}

input FormInput {
    name: String @doc(description: &quot;Get Name&quot;)
    number: String @doc(description: &quot;Get Number&quot;)
    email: String @doc(description: &quot;Get Email&quot;)
    password: String @doc(description: &quot;Get Password&quot;)
    gender: Int @doc(description: &quot;Get Gender&quot;)
    bdate: String @doc(description: &quot;Get Birth Date&quot;)
}

type FormOutput {
   success_message: String @doc(description: &quot;Success Message&quot;)
}
</code></pre></div>



<p>Explanation of graphql :-</p>



<ul>
<li>type Mutation &gt; declares Mutation operations of our module.</li>



<li>dataFormSubmit &gt; name of our Mutation.</li>



<li>FormInput &gt; it is input value and type.</li>



<li>FormOutput &gt; declares output message.</li>
</ul>



<p><strong>Step 4 :-</strong>&nbsp;Create Resolver Class&nbsp;<strong><code>Model/Resolver/FormDataSave.php</code></strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="FormDataSave.php" data-lang="PHP"><code>&lt;?php

namespace Kpyxal\MutationGraphql\Model\Resolver;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Kpyxal\MutationGraphql\Api\TestRepositoryInterface;
use Kpyxal\MutationGraphql\Api\Data\TestInterface;


class FormDataSave implements ResolverInterface
{
    private $contactusDataProvider;

    /**
     * @param
     */
    public function __construct(
        TestRepositoryInterface $testRepository,
        TestInterface $testInterface
    ) {
        $this-&gt;_testRepository=$testRepository;
        $this-&gt;_testModel = $testInterface;
    }

    /**
     * @inheritdoc
     */
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {

        $name = $args[&#39;input&#39;][&#39;name&#39;];
        $number = $args[&#39;input&#39;][&#39;number&#39;];
        $email = $args[&#39;input&#39;][&#39;email&#39;];
        $password = $args[&#39;input&#39;][&#39;password&#39;];
        $gender = $args[&#39;input&#39;][&#39;gender&#39;];
        $bdate = $args[&#39;input&#39;][&#39;bdate&#39;];

        $this-&gt;_testModel-&gt;setName($name);
        $this-&gt;_testModel-&gt;setNumber($number);
        $this-&gt;_testModel-&gt;setEmail($email);
        $this-&gt;_testModel-&gt;setPassword($password);
        $this-&gt;_testModel-&gt;setGender($gender);
        $this-&gt;_testModel-&gt;setBdate($bdate); 
        $thanks_message = [];

        try {
            $this-&gt;_testRepository-&gt;save($this-&gt;_testModel);
            $thanks_message[&#39;success_message&#39;]=&quot;Successfully Added&quot;;
        } catch (CouldNotSaveException $e) {
            $thanks_message[&#39;success_message&#39;]=&quot;Something went wrong.&quot;;
        }
        return $thanks_message;
    }
}</code></pre></div>



<p>Here in above resolver file we used:- </p>



<p><br>Kpyxal\MutationGraphql\Api\TestRepositoryInterface;<br>Kpyxal\MutationGraphql\Api\Data\TestInterface;<br><br>Additionally, the repository and interface file are designed to save fields such as email, name, and number.<br><strong>Step 6 :-</strong>&nbsp;Final step you check output. Run this query</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>mutation {
    contactusFormSubmit(
        input:{
            name: &quot;KPYXAL&quot;
            number: &quot;+123456798&quot;
            email: &quot;TEST@TEST.COM&quot;
            password: &quot;pass@123&quot;
            gender: &quot;1&quot;
            bdate: &quot;28/08/2222&quot;       
        }
    ){
        success_message
    }
}</code></pre></div>



<p>To sum up, mutations in GraphQL are essential for altering data within your application. They not only allow for the creation, update, or deletion of objects but also offer flexibility through various elements such as operation names and input objects. While mutations function akin to POST, PUT, and DELETE requests in REST, their integration with GraphQL&#8217;s robust query language provides a powerful toolset for managing data efficiently. As we continue to explore GraphQL, ultimately, understanding these components will help, significantly,  in harnessing the full potential of this dynamic query language.<br><strong>Happy Coding ..!</strong> <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>Check more blogs like this:</p>



<ul>
<li><a href="https://www.kpyxal.com/magento/graphql/query-in-graphql/">Query in GRAPHQL</a></li>



<li><a href="https://www.kpyxal.com/magento/magento-2-4-5-installation-on-ubuntu/">Magento 2.4.5 Installation on ubuntu</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://www.kpyxal.com/magento/mutation-in-graphql/">Mutation in GRAPHQL</a> appeared first on <a rel="nofollow" href="https://www.kpyxal.com">Kpyxal Solutions LLP</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kpyxal.com/magento/mutation-in-graphql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Magento2 Query in GRAPHQL</title>
		<link>https://www.kpyxal.com/magento/graphql/query-in-graphql/</link>
					<comments>https://www.kpyxal.com/magento/graphql/query-in-graphql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 20 Feb 2023 05:32:36 +0000</pubDate>
				<category><![CDATA[Graphql]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[adobe commerce]]></category>
		<category><![CDATA[expert exam with cloud addon AD0-E716]]></category>
		<category><![CDATA[graphql query example]]></category>
		<category><![CDATA[Kpyxal Solutions LLP]]></category>
		<category><![CDATA[magento2 graphql]]></category>
		<category><![CDATA[magento2 query graphql]]></category>
		<guid isPermaLink="false">https://www.kpyxal.com/?p=84</guid>

					<description><![CDATA[<p>Magento2 Query in GRAPHQL retrieves data from the application server similar to a REST GET call. Additionally, Adobe Commerce and Magento Open Source GraphQL queries enable mobile apps or browsers to display a diverse range of information, including: Implementation Magento2 Query in GRAPHQL Built into Magento 2.4, GraphQL support simplifies data retrieval. The following sections [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.kpyxal.com/magento/graphql/query-in-graphql/">Magento2 Query in GRAPHQL</a> appeared first on <a rel="nofollow" href="https://www.kpyxal.com">Kpyxal Solutions LLP</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Magento2 Query in GRAPHQL retrieves data from the application server similar to a REST GET call. Additionally, Adobe Commerce and Magento Open Source GraphQL queries enable mobile apps or browsers to display a diverse range of information, including:</p>



<ul>
<li>A set of products to be displayed. This can include the entire catalog or those that match customer-specified criteria.</li>



<li>A customer token allows a query to access basic information, billing and shipping addresses, wish lists, order history, and other sensitive data. Moreover, GraphQL can also retrieve shopping cart contents for both guest and logged-in customers</li>



<li>Shopping cart contents. GraphQL supports both guest and logged-in customer carts.</li>



<li>Store configuration values, including theme and CMS settings, the currency code, and supported countries.</li>
</ul>



<h2><strong>Implementation</strong> Magento2 Query in GRAPHQL </h2>



<p>Built into Magento 2.4, GraphQL support simplifies data retrieval. The following sections will detail the step-by-step implementation process and provide an example of a Magento2 Query in GRAPHQL.</p>



<p><strong>Step 1 :-</strong>&nbsp;You Create&nbsp;<strong><code>registration.php</code></strong>&nbsp;file</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="registration.php" data-lang="PHP"><code>&lt;?php
/**
 * @author KPYXAL
 * @copyright Copyright (c) 2021
 * @package Kpyxal_GraphqlQuery
 */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    &#39;Kpyxal_GraphqlQuery&#39;,
    __DIR__
);</code></pre></div>



<p><strong>Step 2 :-</strong>&nbsp;create&nbsp;<strong><code>etc/module.xml</code></strong>&nbsp;file</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="module.xml" data-lang="PHP"><code>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!--
/**
 * @author KPYXAL
 * @copyright Copyright (c) 2021
 * @package Kpyxal_GraphqlQuery
 */
--&gt;

&lt;config xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module/etc/module.xsd&quot;&gt;
    &lt;module name=&quot;Kpyxal_GraphqlQuery&quot; &gt;
        &lt;sequence&gt;
            &lt;module name=&quot;Magento_Customer&quot;/&gt;
            &lt;module name=&quot;Magento_Authorization&quot;/&gt;
            &lt;module name=&quot;Magento_GraphQl&quot;/&gt;
        &lt;/sequence&gt;
    &lt;/module&gt;
&lt;/config&gt;</code></pre></div>



<p><strong>Step 3 :-</strong>&nbsp;GraphQL queries are declared under&nbsp;<strong><code>etc/schema.graphqls</code></strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="schema.graphqls" data-lang="PHP"><code>type Query {
    formdata: [Formdata] @resolver(class:&quot;Kpyxal\\GraphqlQuery\\Model\\Resolver\\ProductsResolver&quot;) @doc(description:&quot;The formdata query returns information about a customer&quot;)
}
type Formdata @doc(description: &quot;Formdata defines the customer name and other details&quot;) {
    name: String @doc(description: &quot;Get Name&quot;)
    number: String @doc(description: &quot;Get Number&quot;)
    email: String @doc(description: &quot;Get Email&quot;)
    password: String @doc(description: &quot;Get Password&quot;)
    gender: Int @doc(description: &quot;Get Gender&quot;)
    bdate: String @doc(description: &quot;Get Birth Date&quot;)
}
</code></pre></div>



<p>In the above file, the file specifies that &#8216;type Query&#8217; declares the query operations for our module; furthermore, it highlights the structure and functionality that are essential for proper implementation.</p>



<p> <strong>&#8216;formdata&#8217;</strong> represents the query name, while <strong>&#8216;type Formdata&#8217;</strong> outlines the query’s structure, including the resolver (@resolver) class and documentation (@doc).</p>



<p><strong>formdata: [Formdata]&nbsp;</strong> :&nbsp; if we need array of data than need to put identity in array like:-<br>name of query = <strong>[</strong> Identity name <strong>]</strong>.<br>Here identity name is <strong>Formdata</strong> same name which we are use in : <strong>type Formdata</strong>&nbsp;</p>



<p><strong>Step 4 :-</strong>&nbsp;Create Resolver Class&nbsp;<strong><code>Model/Resolver/ProductsResolver.php</code></strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-file="ProductsResolver.php" data-lang="PHP"><code>&lt;?php
declare(strict_types=1);

namespace Kpyxal\GraphqlQuery\Model\Resolver;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Kpyxal\GraphqlQuery\Model\ResourceModel\Test\Collection;

/**
 * Product collection resolver
 */
class ProductsResolver implements ResolverInterface
{
    public function __construct(
        \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
        Collection $collection
    ) {
        $this-&gt;searchCriteriaBuilder = $searchCriteriaBuilder;
        $this-&gt;collection = $collection;
    }

    /**
     * @inheritdoc
     */
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        $alldata = $this-&gt;getAllData();
        $arraydata= [];
        if (count($alldata) &gt; 0):
            foreach ($alldata as $data):
                 $arraydata[] = array(
                            &#39;name&#39;=&gt;$data-&gt;getName(),
                            &#39;number&#39;=&gt;$data-&gt;getNumber(),
                            &#39;email&#39;=&gt;$data-&gt;getEmail(),
                            &#39;password&#39;=&gt;$data-&gt;getPassword(),
                            &#39;gender&#39;=&gt;$data-&gt;getGender(),
                            &#39;bdate&#39;=&gt;$data-&gt;getBdate()
                        );
            endforeach;
        endif;
        return $arraydata;
    }

    /**
     * @return Collection
     */
    public function getAllData()
    {
        return $this-&gt;collection;
    }
}
</code></pre></div>



<p>The resolver file utilizes </p>



<p><em>Kpyxal\GraphqlQuery\Model\ResourceModel\Test\Collection </em></p>



<p>to gather data. This data is then assigned to variables including name, number, and email.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>{
    formdata{
        name
        number
        email
        password
        gender
        bdate
    }
}</code></pre></div>



<p>In conclusion, <a href="https://account.magento.com/customer/account/login">Magento2</a> Query in GRAPHQL offer a powerful way to retrieve data from the application server, similar to a REST GET call. They provide flexibility in accessing a wide range of information; consequently,&nbsp;enabling mobile apps or browsers to render content efficiently, making it an ideal solution for modern, headless commerce applications.</p>



<p><strong>Happy Coding ..!</strong> <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>Check More Like This </p>



<p>&#8211;<a href="https://www.kpyxal.com/magento/magento-2-4-5-installation-on-ubuntu/">Magento 2.4.5 Installation on ubuntu</a></p>
<p>The post <a rel="nofollow" href="https://www.kpyxal.com/magento/graphql/query-in-graphql/">Magento2 Query in GRAPHQL</a> appeared first on <a rel="nofollow" href="https://www.kpyxal.com">Kpyxal Solutions LLP</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kpyxal.com/magento/graphql/query-in-graphql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
