Customer GraphQL Query in Magento to retrieve basic information of the customer entity.
Using Customer Query, You can fetch the data of the logged-in customer by adding the customer access token as Headers.
schema.graphql
file for the Customer module will be defined at, vendor/magento/module-customer-graph-ql/etc/schema.graphqls
Syntax:
1 2 3 | type Query { customer: Customer } |
Customer Object contains multiple attribute fields.
1.) Generate Customer Token and set it with Bearer value,
Authorization Bearer {CUSTOMER_TOKEN}
2) Customer GraphQL Query,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | { customer { firstname middlename lastname suffix prefix gender date_of_birth taxvat created_at default_shipping default_billing email is_subscribed addresses { firstname lastname street city region { region_code region } postcode vat_id country_code telephone company } } } |
The output of the Customer GraphQL Query will be data of the specific customer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | { "data": { "customer": { "firstname": "Rakesh", "middlename": "B.", "lastname": "Jesadiya", "suffix": "Mr", "prefix": null, "gender": null, "date_of_birth": null, "taxvat": null, "created_at": "2020-10-18 22:16:12", "default_shipping": "2", "default_billing": "2", "email": "rakesh@jesadiya.com", "is_subscribed": true "addresses": [ { "firstname": "Rakesh", "lastname": "Jesadiya", "street": [ "Spice Street" ], "city": "cityName", "region": { "region_code": "CA", "region": "California" }, "postcode": "45454", "country_code": "US", "telephone": "121222222", "company": null } ] } } } |
If any attribute value will be null, the Response GraphQL value will be null otherwise display the specific value of the attribute.