0

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?

  • Did you try to pass that attribute in the CustomerInput, i am asking this based on the product Attribute, If we create a custom product attribute we can get the value by just passing the attribute_code in the query. – Mujahidh Oct 16 '19 at 5:24
  • How can I extend the CustomerInput in vendor ? – Kavi Oct 16 '19 at 5:35
  • Can you just elaborate on this? – Kavi Oct 16 '19 at 5:36
  • you just pass your new attribute in CustomerInput and see, but currently CustomerInput only have prefix,firstname,middlename,lastname,suffix,email,dob,taxvat,gender,password,is_subscribed fields.if passing the attribute to the mutation not work you have to write your own module to add the attribute and do some work arround in Magento\\CustomerGraphQl\\Model\\Resolver\\CreateCustomer in your own module. – Mujahidh Oct 16 '19 at 5:43
  • study the module-customer-graph-ql in vendor/magento directory. – Mujahidh Oct 16 '19 at 5:44
0

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
    }
  }
}
| improve this answer | |
  • this way not working for me... – prabhakaran7 Dec 17 '19 at 5: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.