Magento Wishlist supports the GraphQL query feature. You can refer to the module-wishlist-graph-ql
from the Magento core code to get more info on the specific query feature.
The schema.graphql
file for the Wishlist module will be available at the path, vendor/magento/module-wishlist-graph-ql/etc/schema.graphqls
You must have enabled the Wishlist feature to get the output of the query by Stores -> Configuration -> Customers -> Wish List -> General Options -> Enable -> Yes.
If you have a disabled wishlist from the configuration and try to execute a wishlist query, it will throw an Error message, The wishlist configuration is currently disabled.
If wishlist settings enable and want to try to execute a query, you will get an expected output,
Syntax:
1 2 3 | type Customer { wishlist: Wishlist! } |
Steps to Execute Wishlist Query by GraphQL Altair App,
- Generate Customer Tokenand set it with Bearer value,
Authorization Bearer {CUSTOMER_TOKEN} - Wishlist GraphQL Query,1234567891011121314151617181920212223242526272829303132333435363738394041{customer {wishlist {items_countsharing_codeupdated_atitems {idqtydescriptionadded_atproduct {skuname... on BundleProduct {skudynamic_sku}... on ConfigurableProduct {skuconfigurable_options {idattribute_id_v2attribute_codelabel__typenameuse_defaultvalues {store_labelswatch_data {value}use_default_value}}}}}}}}
A Wishlist is the part of Customer Query from Magento 2.4.
Earlier you can use query wishlist {}
but The wishlist query has been deprecated from the 2.4 Version.
Always use the best standard with taking parent as customer{} query and define your wishlist inside it.
As per the above query, we have to use the latest query feature without the deprecated method.
Output:
I have added one simple and one configurable item to the wishlist,
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | { "data": { "customer": { "wishlist": { "items_count": 2, "sharing_code": "9xDTH0sApItwqk84eOs1w931jD2RWc4H", "updated_at": "2020-10-19 08:16:27", "items": [ { "id": 14, "qty": 2, "description": null, "added_at": "2020-10-27 13:24:59", "product": { "sku": "24-MB04", "name": "Strive Shoulder Pack" } }, { "id": 16, "qty": 1, "description": null, "added_at": "2020-10-27 13:27:37", "product": { "sku": "MH01", "name": "Chaz Kangeroo Hoodie", "configurable_options": [ { "id": 3, "attribute_id_v2": 93, "attribute_code": "color", "label": "Color", "__typename": "ConfigurableProductOptions", "use_default": false, "values": [ { "store_label": "Black", "swatch_data": { "value": "#000000" }, "use_default_value": true }, { "store_label": "Gray", "swatch_data": { "value": "#8f8f8f" }, "use_default_value": true }, { "store_label": "Orange", "swatch_data": { "value": "#eb6703" }, "use_default_value": true } ] }, { "id": 2, "attribute_id_v2": 186, "attribute_code": "size", "label": "Size", "__typename": "ConfigurableProductOptions", "use_default": false, "values": [ { "store_label": "XS", "swatch_data": { "value": "XS" }, "use_default_value": true }, { "store_label": "S", "swatch_data": { "value": "S" }, "use_default_value": true }, { "store_label": "M", "swatch_data": { "value": "M" }, "use_default_value": true }, { "store_label": "L", "swatch_data": { "value": "L" }, "use_default_value": true }, { "store_label": "XL", "swatch_data": { "value": "XL" }, "use_default_value": true } ] } ] } } ] } } } } |
You can use only the required field in your output to improve performance instead of getting all the fields in the payload.
If you want to explore the product full details, use the ... on ConfigurableProduct {}
for the configurable item, ... on BundleProduct {}
for the bundle item and ... on DownloadableProduct {}
for the downloadable item.