Skip to content

Commit 9a867d9

Browse files
lkostrowskiclaude
andcommitted
Replace deprecated attributes with assignedAttributes in product list query
Migrate the product list from the deprecated `Product.attributes` (SelectedAttribute) to the new `Product.assignedAttributes` (AssignedAttribute interface) introduced in Saleor 3.22. This is PR 1 of 3 in the incremental migration. Changes: - Add ProductListAssignedAttribute fragment with typed inline fragments for all 20+ AssignedAttribute implementations, using field aliases to avoid GraphQL merging conflicts - Update productListQuery to use assignedAttributes instead of attributes - Add getDisplayValueFromAssignedAttribute() utility for extracting display text from typed AssignedAttribute union members - Update ProductListDatagrid to use the new field and utility - Update product list fixtures to match the new AssignedAttribute shape Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e5a6dbd commit 9a867d9

7 files changed

Lines changed: 385 additions & 324 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { type ProductListQuery } from "@dashboard/graphql";
2+
import { type RelayToFlat } from "@dashboard/types";
3+
4+
type ProductListItems = NonNullable<RelayToFlat<ProductListQuery["products"]>>;
5+
type AssignedAttributeItem = ProductListItems[number]["assignedAttributes"][number];
6+
7+
export function getDisplayValueFromAssignedAttribute(attr: AssignedAttributeItem): string {
8+
switch (attr.__typename) {
9+
case "AssignedSingleChoiceAttribute":
10+
return attr.singleChoiceValue?.name ?? "";
11+
case "AssignedMultiChoiceAttribute":
12+
return attr.multiChoiceValue.map((v: { name: string | null }) => v.name).join(", ");
13+
case "AssignedNumericAttribute":
14+
return attr.numericValue != null ? String(attr.numericValue) : "";
15+
case "AssignedPlainTextAttribute":
16+
return attr.plainTextValue ?? "";
17+
case "AssignedBooleanAttribute":
18+
return attr.booleanValue != null ? String(attr.booleanValue) : "";
19+
case "AssignedDateAttribute":
20+
return attr.dateValue ?? "";
21+
case "AssignedDateTimeAttribute":
22+
return attr.dateTimeValue ?? "";
23+
case "AssignedSwatchAttribute":
24+
return attr.swatchValue?.name ?? "";
25+
case "AssignedSinglePageReferenceAttribute":
26+
return attr.pageReferenceValue?.title ?? "";
27+
case "AssignedSingleProductReferenceAttribute":
28+
return attr.productReferenceValue?.name ?? "";
29+
case "AssignedSingleProductVariantReferenceAttribute":
30+
return attr.variantReferenceValue?.name ?? "";
31+
case "AssignedSingleCategoryReferenceAttribute":
32+
return attr.categoryReferenceValue?.name ?? "";
33+
case "AssignedSingleCollectionReferenceAttribute":
34+
return attr.collectionReferenceValue?.name ?? "";
35+
case "AssignedMultiPageReferenceAttribute":
36+
return attr.multiPageReferenceValue.map((v: { title: string }) => v.title).join(", ");
37+
case "AssignedMultiProductReferenceAttribute":
38+
return attr.multiProductReferenceValue.map((v: { name: string }) => v.name).join(", ");
39+
case "AssignedMultiProductVariantReferenceAttribute":
40+
return attr.multiVariantReferenceValue.map((v: { name: string }) => v.name).join(", ");
41+
case "AssignedMultiCategoryReferenceAttribute":
42+
return attr.multiCategoryReferenceValue.map((v: { name: string }) => v.name).join(", ");
43+
case "AssignedMultiCollectionReferenceAttribute":
44+
return attr.multiCollectionReferenceValue.map((v: { name: string }) => v.name).join(", ");
45+
default:
46+
return "";
47+
}
48+
}

src/fragments/products.ts

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,90 @@ export const exportFileFragment = gql`
410410
}
411411
`;
412412

413-
export const productListAttribute = gql`
414-
fragment ProductListAttribute on SelectedAttribute {
413+
export const productListAssignedAttribute = gql`
414+
fragment ProductListAssignedAttribute on AssignedAttribute {
415415
attribute {
416416
id
417417
}
418-
values {
419-
...AttributeValue
418+
... on AssignedSingleChoiceAttribute {
419+
singleChoiceValue: value {
420+
name
421+
}
422+
}
423+
... on AssignedMultiChoiceAttribute {
424+
multiChoiceValue: value {
425+
name
426+
}
427+
}
428+
... on AssignedNumericAttribute {
429+
numericValue: value
430+
}
431+
... on AssignedPlainTextAttribute {
432+
plainTextValue: value
433+
}
434+
... on AssignedBooleanAttribute {
435+
booleanValue: value
436+
}
437+
... on AssignedDateAttribute {
438+
dateValue: value
439+
}
440+
... on AssignedDateTimeAttribute {
441+
dateTimeValue: value
442+
}
443+
... on AssignedSwatchAttribute {
444+
swatchValue: value {
445+
name
446+
}
447+
}
448+
... on AssignedSinglePageReferenceAttribute {
449+
pageReferenceValue: value {
450+
title
451+
}
452+
}
453+
... on AssignedSingleProductReferenceAttribute {
454+
productReferenceValue: value {
455+
name
456+
}
457+
}
458+
... on AssignedSingleProductVariantReferenceAttribute {
459+
variantReferenceValue: value {
460+
name
461+
}
462+
}
463+
... on AssignedSingleCategoryReferenceAttribute {
464+
categoryReferenceValue: value {
465+
name
466+
}
467+
}
468+
... on AssignedSingleCollectionReferenceAttribute {
469+
collectionReferenceValue: value {
470+
name
471+
}
472+
}
473+
... on AssignedMultiPageReferenceAttribute {
474+
multiPageReferenceValue: value {
475+
title
476+
}
477+
}
478+
... on AssignedMultiProductReferenceAttribute {
479+
multiProductReferenceValue: value {
480+
name
481+
}
482+
}
483+
... on AssignedMultiProductVariantReferenceAttribute {
484+
multiVariantReferenceValue: value {
485+
name
486+
}
487+
}
488+
... on AssignedMultiCategoryReferenceAttribute {
489+
multiCategoryReferenceValue: value {
490+
name
491+
}
492+
}
493+
... on AssignedMultiCollectionReferenceAttribute {
494+
multiCollectionReferenceValue: value {
495+
name
496+
}
420497
}
421498
}
422499
`;

src/graphql/hooks.generated.ts

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,16 +3235,93 @@ export const ExportFileFragmentDoc = gql`
32353235
url
32363236
}
32373237
`;
3238-
export const ProductListAttributeFragmentDoc = gql`
3239-
fragment ProductListAttribute on SelectedAttribute {
3238+
export const ProductListAssignedAttributeFragmentDoc = gql`
3239+
fragment ProductListAssignedAttribute on AssignedAttribute {
32403240
attribute {
32413241
id
32423242
}
3243-
values {
3244-
...AttributeValue
3243+
... on AssignedSingleChoiceAttribute {
3244+
singleChoiceValue: value {
3245+
name
3246+
}
3247+
}
3248+
... on AssignedMultiChoiceAttribute {
3249+
multiChoiceValue: value {
3250+
name
3251+
}
3252+
}
3253+
... on AssignedNumericAttribute {
3254+
numericValue: value
3255+
}
3256+
... on AssignedPlainTextAttribute {
3257+
plainTextValue: value
3258+
}
3259+
... on AssignedBooleanAttribute {
3260+
booleanValue: value
3261+
}
3262+
... on AssignedDateAttribute {
3263+
dateValue: value
3264+
}
3265+
... on AssignedDateTimeAttribute {
3266+
dateTimeValue: value
3267+
}
3268+
... on AssignedSwatchAttribute {
3269+
swatchValue: value {
3270+
name
3271+
}
3272+
}
3273+
... on AssignedSinglePageReferenceAttribute {
3274+
pageReferenceValue: value {
3275+
title
3276+
}
3277+
}
3278+
... on AssignedSingleProductReferenceAttribute {
3279+
productReferenceValue: value {
3280+
name
3281+
}
3282+
}
3283+
... on AssignedSingleProductVariantReferenceAttribute {
3284+
variantReferenceValue: value {
3285+
name
3286+
}
3287+
}
3288+
... on AssignedSingleCategoryReferenceAttribute {
3289+
categoryReferenceValue: value {
3290+
name
3291+
}
3292+
}
3293+
... on AssignedSingleCollectionReferenceAttribute {
3294+
collectionReferenceValue: value {
3295+
name
3296+
}
3297+
}
3298+
... on AssignedMultiPageReferenceAttribute {
3299+
multiPageReferenceValue: value {
3300+
title
3301+
}
3302+
}
3303+
... on AssignedMultiProductReferenceAttribute {
3304+
multiProductReferenceValue: value {
3305+
name
3306+
}
3307+
}
3308+
... on AssignedMultiProductVariantReferenceAttribute {
3309+
multiVariantReferenceValue: value {
3310+
name
3311+
}
3312+
}
3313+
... on AssignedMultiCategoryReferenceAttribute {
3314+
multiCategoryReferenceValue: value {
3315+
name
3316+
}
3317+
}
3318+
... on AssignedMultiCollectionReferenceAttribute {
3319+
multiCollectionReferenceValue: value {
3320+
name
3321+
}
32453322
}
32463323
}
3247-
${AttributeValueFragmentDoc}`;
3324+
`;
32483325
export const ShippingMethodWithPostalCodesFragmentDoc = gql`
32493326
fragment ShippingMethodWithPostalCodes on ShippingMethodType {
32503327
id
@@ -15821,8 +15898,8 @@ export const ProductListDocument = gql`
1582115898
updatedAt
1582215899
created
1582315900
description
15824-
attributes {
15825-
...ProductListAttribute
15901+
assignedAttributes {
15902+
...ProductListAssignedAttribute
1582615903
}
1582715904
}
1582815905
}
@@ -15836,7 +15913,7 @@ export const ProductListDocument = gql`
1583615913
}
1583715914
}
1583815915
${ProductWithChannelListingsFragmentDoc}
15839-
${ProductListAttributeFragmentDoc}`;
15916+
${ProductListAssignedAttributeFragmentDoc}`;
1584015917

1584115918
/**
1584215919
* __useProductListQuery__

0 commit comments

Comments
 (0)