I Have created a module to add custom attribute to createCustomer mutation.
Vendor/Module/etc/extension_attributes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="custom_attr" type="string"/>
</extension_attributes>
Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Api\Data\CustomerInterface">
<arguments>
<argument name="extensionAttributesObjects" xsi:type="array">
<item name="custom_attr" xsi:type="string">Vendor\Module\Api\Data\CustomerExtensionInterface</item>
</argument>
</arguments>
</type>
Vendor\Module\Api\Data\CustomerExtensionInterface.php
<?php
namespace Vendor\Module\Api\Data;
interface CustomerExtensionInterface
{
/**
* Get customAttr
*
* @return string|null
*/
public function getCustomAttr(): ?string;
/**
* Set custom_attr
*
* @param string|null $custom_attr
* @return $this
*/
public function setCustomAttr(?string $custom_attr): self;
}
Now I am trying this request in createCustomer Mutattion
mutation {
createCustomer(
input: {
firstname: "test"
lastname: "test"
email: "[email protected]"
is_subscribed: true
custom_attr: "test value"
}
) {
customer {
id
firstname
lastname
email
}
}
}
Note: created the "custom_attr" customer attribute with data patch.
Getting below error
"message": "Field "custom_attr" is not defined by type CustomerInput.",
Can someone help me on this how to custom attribute in the create customer mutation in graphQL.