Skip to content

Commit 9011ac7

Browse files
authored
Merge pull request #396 from magento/propose-changes-to-id_v2
Propose renaming id_v2 to something more permanent, and change type
2 parents f335eb5 + 54174a6 commit 9011ac7

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

design-documents/graph-ql/coverage/add-items-to-cart-single-mutation.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ Each product may have options. Option can be of 2 types (see example below):
3131
]
3232
```
3333

34-
We can consider "Selected Option" and "ID for Entered Option" as UUID. They meet the criteria:
34+
We can consider "Selected Option" and "ID for Entered Option" as a globally unique identifier. They meet the criteria:
3535

3636
- "Selected Option" represents option value, while "ID for Entered Option" represents option
3737
- Must be unique across different options
3838
- Returned from server
39-
- Used by client as is
39+
- Used by client as is (opaque)
4040

4141
Selected options can be used for:
4242
- Customizable options such as dropdwon, radiobutton, checkbox, etc
@@ -51,14 +51,22 @@ Entered options:
5151

5252
#### Option implementation
5353

54-
Product schema should be extended in order to provide option identifier (aka first iteration of "UUID").
55-
Until introducing UUID lets name this identifier as *"id_v2"
54+
Product schema should be extended in order to provide option identifier (aka first iteration of "UUID"). This field will be named `uid` (unique identifier, or universal ID).
5655

57-
Option *id_v2* is `base64` encoded string, that encodes details for each option and in most cases can be presented as
56+
---
57+
**Note on Field Name**
58+
`uid` was chosen for several reasons:
59+
- `id` is already reserved as an `Int` field in most types, and we want to avoid breaking changes
60+
- `uuid` implies a specific encoding algorithm, and the client shouldn't know or care
61+
- `id_v2` has a temporary-sounding name (`id_v2` makes me think `id_v3` will be coming). However, there is no need to change field names when changing the format of a field that uses the `ID` type, because clients are not meant to be parsing/formatting/inspecting `ID` values. The `uid` field can hold an integer or a base64-encoded value today, and a real UUID in the future, and it will _not_ be a breaking change. `ID` values are always serialized to a string
62+
---
63+
64+
65+
For product options, for now, *uid* is a `base64` encoded string, wrapper in an `ID` type, that encodes details for each option and in most cases can be presented as
5866
`base64("<option-type>/<option-id>/<option-value-id>")`
59-
For example, for customizable drop-down option "Color(id = 1), with values Red(id = 1), Green(id = 2)" id_v2 for Color:Red will looks like `"Y3VzdG9tLW9wdGlvbi8xLzE=" => base64("custom-option/1/1")`
67+
For example, for customizable drop-down option "Color(id = 1), with values Red(id = 1), Green(id = 2)" `uid` for Color:Red will looks like `"Y3VzdG9tLW9wdGlvbi8xLzE=" => base64("custom-option/1/1")`
6068

61-
Here is a GQL query that shows how to add a new field "id_v2: String!" to cover existing cases:
69+
Here is a GQL query that shows how to add a new field "uid: ID!" to cover existing cases:
6270

6371

6472
``` graphql
@@ -73,15 +81,15 @@ query {
7381
... on CustomizableRadioOption {
7482
title
7583
value {
76-
id_v2 # introduce new id_v2 field in CustomizableRadioValue
84+
uid # introduce new uid field in CustomizableRadioValue
7785
option_type_id
7886
title
7987
}
8088
}
8189
... on CustomizableDropDownOption {
8290
title
8391
value {
84-
id_v2 # introduce new id_v2 field in CustomizableDropDownValue
92+
uid # introduce new uid field in CustomizableDropDownValue
8593
# see \Magento\QuoteGraphQl\Model\Cart\BuyRequest\CustomizableOptionsDataProvider
8694
option_type_id
8795
title
@@ -92,15 +100,15 @@ query {
92100
} ... on ConfigurableProduct {
93101
variants {
94102
attributes {
95-
id_v2 # introduce new id_v2 field in ConfigurableAttributeOption (format: configurable/<attribute-id>/<value_index>)
103+
uid # introduce new uid field in ConfigurableAttributeOption (format: configurable/<attribute-id>/<value_index>)
96104
# see \Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider
97105
code
98106
value_index
99107
}
100108
}
101109
} ... on DownloadableProduct {
102110
downloadable_product_links {
103-
id_v2 # introduce new id_v2 field in DownloadableProductLinks (format: downloadable/link/<link_id>)
111+
uid # introduce new uid field in DownloadableProductLinks (format: downloadable/link/<link_id>)
104112
# see \Magento\DownloadableGraphQl\Model\Cart\BuyRequest\DownloadableLinksDataProvider
105113
title
106114
}
@@ -109,15 +117,15 @@ query {
109117
sku
110118
title
111119
options {
112-
id_v2 # introduce new id_v2 field in BundleItemOption (format: bundle/<option-id>/<option-value-id>/<option-quantity>)
120+
uid # introduce new uid field in BundleItemOption (format: bundle/<option-id>/<option-value-id>/<option-quantity>)
113121
# see \Magento\BundleGraphQl\Model\Cart\BuyRequest\BundleDataProvider
114122
id
115123
label
116124
}
117125
}
118126
} ... on GiftCardProduct {
119127
giftcard_amounts {
120-
id_v2 # introduce new id_v2 field in GiftCardAmounts (format: giftcard/...TBD)
128+
uid # introduce new uid field in GiftCardAmounts (format: giftcard/...TBD)
121129
# see \Magento\GiftCard\Model\Quote\Item\CartItemProcessor::convertToBuyRequest
122130
value_id
123131
website_id
@@ -154,7 +162,7 @@ query {
154162

155163
In this example we want to add _personalized blue cup to cart_ to cart.
156164

157-
- `selected_options` - predefined and selected by customer options. `base64` encoding will help to use UUID in future.
165+
- `selected_options` - predefined and selected by customer options. `base64` encoding is temporary until Magento supports UUIDs, but this is unknown to the client and purely a server implementation detail.
158166
:warning: The encoded value will be returned from server and should be used by client as is.
159167

160168
In this example values will be following:

0 commit comments

Comments
 (0)