Ergonode docs
GraphQL API
Search…
⌃K

AttributeValue migration guide

Keeping in mind future extendibility we came to the conclusion that the current API schema does not support the attribute values best. It bases on attribute value type which basically comes down to string, numeric representations shared among different attribute types.
Whenever a change is required it touches all other attribute types with the same value type.
Your current query looked probably something like this
{
product(sku: "SKU") {
sku
attributeList {
edges {
node {
... AttributeValue
}
}
}
}
}
fragment AttributeValue on AttributeValue {
__typename
attribute {
code
}
valueTranslations {
__typename
language
... on StringAttributeValue {
stringValue: value
}
... on NumericAttributeValue {
numericValue: value
}
... on StringArrayAttributeValue {
stringArrayValue: value
}
... on MultimediaArrayAttributeValue {
multimediaArrayValue: value {
... Multimedia
}
}
... on MultimediaAttributeValue {
multimediaValue: value {
... Multimedia
}
}
... on ProductArrayAttributeValue {
productArrayValue: value {
sku
}
}
}
}
fragment Multimedia on Multimedia {
name
extension
mime
size
alt {
value
language
}
title {
value
language
}
url
}
With the new schema, you can write the query with a very similar result in mind - grouping the values by the represented value type.
Since the option attributes are represented in a different way - now representing entire options rather than their codes the output in those types is a bit different those values will have to be returned differentely
{
product(sku: "SKU") {
sku
attributeList {
edges {
node {
attribute {
code
}
translations {
__typename
language
... on TextAttributeValueTranslation {
stringValue: value
}
... on TextareaAttributeValueTranslation {
stringValue: value
}
... on DateAttributeValueTranslation {
stringValue: value
}
... on UnitAttributeValueTranslation {
numericValue: value
}
... on PriceAttributeValueTranslation {
numericValue: value
}
... on NumericAttributeValueTranslation {
numericValue: value
}
... on ProductRelationAttributeValueTranslation {
productArrayValue: value {
sku
}
}
... on FileAttributeValueTranslation {
multimediaArrayValue: value {
... Multimedia
}
}
... on GalleryAttributeValueTranslation {
multimediaArrayValue: value {
... Multimedia
}
}
... on ImageAttributeValueTranslation {
multimediaValue: value {
... Multimedia
}
}
... on MultiSelectAttributeValueTranslation {
optionArrayValue: value {
... Option
}
}
... on SelectAttributeValueTranslation {
optionValue: value {
... Option
}
}
}
}
}
}
}
}
fragment Multimedia on Multimedia {
name
extension
mime
size
alt {
value
language
}
title {
value
language
}
url
}
fragment Option on Option {
code
name {
value
language
}
}
The new schema also grants you the possibility of easier unpacking of specific attribute types. Since AttributeValue type also recevided specific per attribute type you can write queries with conditional on this level - note unit and price attributes - there's no need to make separate unpacking of attribute list and values.
{
product(sku: "SKU") {
sku
attributeList {
edges {
node {
... AttributeValue
}
}
}
}
}
fragment AttributeValue on AttributeValue {
__typename
attribute {
code
}
... on TextAttributeValue {
textAttributeValueTranslations: translations {
value
language
}
}
... on TextareaAttributeValue {
textareaAttributeValueTranslations: translations {
value
language
}
}
... on DateAttributeValue {
dateAttributeValueTranslations: translations {
value
language
}
}
... on UnitAttributeValue {
unitAttribute: attribute { # unit might be useful in the value context
unit {
name
symbol
}
}
unitAttributeValueTranslations: translations {
value
language
}
}
... on PriceAttributeValue {
priceAttribute: attribute { # currency might be useful in the price context
currency
}
priceAttributeValueTranslations: translations {
value
language
}
}
... on NumberAttributeValue {
numericAttributeValueTranslations: translations {
value
language
}
}
... on ProductRelationAttributeValue {
productRelationAttributeValueTranslations: translations {
value {
sku
}
language
}
}
... on FileAttributeValue {
fileAttributeValueTranslations: translations {
value {
... Multimedia
}
language
}
}
... on GalleryAttributeValue {
galleryAttributeValueTranslations: translations {
value {
... Multimedia
}
language
}
}
... on ImageAttributeValue {
imageAttributeValueTranslations: translations {
value {
... Multimedia
}
language
}
}
... on MultiSelectAttributeValue {
multiSelectAttributeValueTranslations: translations {
value {
... Option
}
language
}
}
... on SelectAttributeValue {
selectAttributeValueTranslations: translations {
value {
... Option
}
language
}
}
}
fragment Multimedia on Multimedia {
path
name
extension
mime
size
alt {
value
language
}
title {
value
language
}
url
}
fragment Option on Option {
code
name {
value
language
}
}
Wrapping things up the new value schema allows you not only to write a query providing a very similar result to the previous approach but also we trust is much more flexible and resistant to future changes.