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="MagentoCustomerApiDataCustomerInterface">
<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="MagentoCustomerApiDataCustomerInterface">
<arguments>
<argument name="extensionAttributesObjects" xsi:type="array">
<item name="custom_attr" xsi:type="string">VendorModuleApiDataCustomerExtensionInterface</item>
</argument>
</arguments>
</type>
VendorModuleApiDataCustomerExtensionInterface.php
<?php
namespace VendorModuleApiData;
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.