my custom module


input CustomerInput {
    sample_attribute: String @doc(description: "new attribute")

but not adding this attribute in customer mutation

magento 2 graphql

I created a custom attribute in Magento backend for Customers


I tried this answer Answer

how I can solve this??


I guess that you are trying to return a new attribute (a custom one) via customer GQL query. The below answer is based on that.

Below is the sample code of adding a custom attribute to Customer GraphQl query.

Module NameSpace : Kcc Module Name : CustomerGraphQl


type Customer {
    sample_attribute: String @resolver(class: "Kcc\\CustomerGraphQl\\Model\\Resolver\\Sample")

The resolver class app/code/Kcc/CustomerGraphQl/Model/Resolver/Sample.php



namespace Kcc\CustomerGraphQl\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 Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellersCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;

class Sample implements ResolverInterface
    public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
        // Return the value of sample_attribute here.
        return 'My sample attr value';

When you run the customer query, it should return the new attribute if requested. enter image description here

  • let me check and inform you..... – prabhakaran7 Jan 7 '20 at 15:26
  • that's one not working.... – prabhakaran7 Jan 9 '20 at 10:36
  • actually I want to add a custom attribute in Createcustomer - mutation – prabhakaran7 Jan 15 '20 at 6:38
  • the issue is to add extra input argument not output – Serhii Havrylchuk May 25 '20 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.