Magento – Adding extension attribute to customer in GraphQL Magento 2

extension-attributesgraphqlmagento2.3

In magento2 – I have created one extension attribute for customer using plugin, it's working fine for Rest API also. How can I include this extension attribute in GraphQL?

In createCustomer mutation , all the CustomerInput are added. Can anyone help me in adding an extension attribute to this mutation?

Best Answer

All you have to do is re-define the 'CustomerInput' parameter (with your custom extension attribute) of the createCustomer mutation.

In your module's schema.graphqls file, re-define the 'CustomerInput' type.

input CustomerInput {
    your_extention_attr: String
}

Then run the below commands.

rm -rf generation/

bin/magento c:f

Now you can parse this new parameter in createCuatomer mutation. See the example below.

mutation {
  createCustomer(
    input: {
      firstname: "Bob"
      lastname: "Loblaw"
      email: "bobldsdd2@example.com"
      password: "b0bl0bl@w"
      is_subscribed: true
      your_extention_attr: "this is a test value"
    }
  ) {
    customer {
      id
      firstname
      lastname
      email
      is_subscribed
    }
  }
}
Related Topic