0

How to get customer group id into graphql magento2

Note: Only in GraphQL

2

2 Answers 2

1

Not much clear what you are looking for. If you want to get the customer group_id in customer graphql query you can directly provide the output variable as below.

{
  customer {
    firstname
    lastname
    suffix
    email
    group_id
  }
}
1
0

Note: This only you'll get if customer is logged in in your Model Resolver file:

protected $_customerSession;

public function __construct(
    \Magento\Customer\Model\Session $customerSession,
) {
    $this->_customerSession = $customerSession;
}

public function getGroupId(){
if($this->_customerSession->isLoggedIn()):
    $customerGroupId = $this->_customerSession->getCustomer()->getGroupId();
endif;
}

After this you can set $customerGroupId variable as a array of your module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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