Skip to content

Commit 04f9469

Browse files
committed
feat(hydrogen-react): add article_reference metafield type support
Storefront API 2025-10 introduces article_reference and list.article_reference metafield types, allowing merchants to reference blog articles in metafields. This adds parsing support following the exact pattern established by page_reference: - Switch cases for single and list reference parsing - Type definitions (ArticleParsedRefMetafield, ArticleListParsedRefMetafield) - Entries in allMetafieldTypesArray and ParsedMetafields - Article added to MetafieldReference union type - Tests for both single and list variants
1 parent bce6ffc commit 04f9469

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@shopify/hydrogen-react': patch
3+
---
4+
5+
Add support for `article_reference` and `list.article_reference` metafield types
6+
7+
These new metafield types were introduced in Storefront API 2025-10, allowing merchants to reference blog articles in metafields.

packages/hydrogen-react/src/parse-metafield.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {getRawMetafield} from './parse-metafield.test.helpers.js';
1010
import {TypeEqual, expectType} from 'ts-expect';
1111
import type {
12+
Article,
1213
Collection,
1314
GenericFile,
1415
MoneyV2,
@@ -27,6 +28,17 @@ import {type RichTextASTNode} from './RichText.types.js';
2728
*/
2829
describe(`parseMetafield`, () => {
2930
describe(`base metafields`, () => {
31+
it(`article_reference`, () => {
32+
const parsed = parseMetafield<ParsedMetafields['article_reference']>({
33+
type: 'article_reference',
34+
reference: {
35+
__typename: 'Article',
36+
},
37+
});
38+
expect(parsed.parsedValue?.__typename === 'Article').toBe(true);
39+
expectType<null | Article>(parsed?.parsedValue);
40+
});
41+
3042
it(`boolean`, () => {
3143
const meta = getRawMetafield({
3244
type: 'boolean',
@@ -278,6 +290,25 @@ describe(`parseMetafield`, () => {
278290
});
279291

280292
describe(`list metafields`, () => {
293+
it(`list.article_reference`, () => {
294+
const parsed = parseMetafield<ParsedMetafields['list.article_reference']>(
295+
{
296+
type: 'list.article_reference',
297+
references: {
298+
nodes: [
299+
{__typename: 'Article', id: '0'},
300+
{__typename: 'Article', id: '1'},
301+
],
302+
},
303+
},
304+
);
305+
parsed.parsedValue?.forEach((article, index) => {
306+
expect(article.__typename === 'Article').toBe(true);
307+
expect(index.toString() === article.id).toBe(true);
308+
});
309+
expectType<null | Article[]>(parsed?.parsedValue);
310+
});
311+
281312
it(`list.collection_reference`, () => {
282313
const parsed = parseMetafield<
283314
ParsedMetafields['list.collection_reference']

packages/hydrogen-react/src/parse-metafield.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
Article,
23
Collection,
34
CurrencyCode,
45
GenericFile,
@@ -44,6 +45,7 @@ export function parseMetafield<ReturnGeneric>(
4445
parsedValue: metafield.value === 'true',
4546
} as ReturnGeneric;
4647

48+
case 'article_reference':
4749
case 'collection_reference':
4850
case 'file_reference':
4951
case 'page_reference':
@@ -156,6 +158,7 @@ export function parseMetafield<ReturnGeneric>(
156158
parsedValue: Number(metafield.value),
157159
} as ReturnGeneric;
158160

161+
case 'list.article_reference':
159162
case 'list.collection_reference':
160163
case 'list.file_reference':
161164
case 'list.page_reference':
@@ -197,6 +200,7 @@ export function parseJSON(json: string): unknown {
197200

198201
// taken from https://shopify.dev/apps/metafields/types
199202
export const allMetafieldTypesArray = [
203+
'article_reference',
200204
'boolean',
201205
'collection_reference',
202206
'color',
@@ -219,6 +223,7 @@ export const allMetafieldTypesArray = [
219223
'volume',
220224
'weight',
221225
// list metafields
226+
'list.article_reference',
222227
'list.collection_reference',
223228
'list.color',
224229
'list.date',
@@ -250,6 +255,8 @@ export type MetafieldTypeTypes = (typeof allMetafieldTypesArray)[number];
250255
* `parsedMetafield.parsedValue`'s type is now `boolean`
251256
*/
252257
export type ParsedMetafields<ExtraTypeGeneric = void> = {
258+
/** A Metafield that's been parsed, with a `parsedValue` of an `Article` object (as defined by the Storefront API) */
259+
article_reference: Simplify<ArticleParsedRefMetafield>;
253260
/** A Metafield that's been parsed, with a `parsedValue` of `boolean` */
254261
boolean: Simplify<BooleanParsedMetafield>;
255262
/** A Metafield that's been parsed, with a `parsedValue` of a `Collection` object (as defined by the Storefront API) */
@@ -299,6 +306,8 @@ export type ParsedMetafields<ExtraTypeGeneric = void> = {
299306
/** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */
300307
weight: Simplify<MeasurementParsedMetafield>;
301308
// list metafields
309+
/** A Metafield that's been parsed, with a `parsedValue` of an array of `Article` objects (as defined by the Storefront API) */
310+
'list.article_reference': Simplify<ArticleListParsedRefMetafield>;
302311
/** A Metafield that's been parsed, with a `parsedValue` of an array of `Collection` objects (as defined by the Storefront API) */
303312
'list.collection_reference': Simplify<CollectionListParsedRefMetafield>;
304313
/** A Metafield that's been parsed, with a `parsedValue` of an array of strings */
@@ -385,6 +394,11 @@ type NumberParsedMetafield = MetafieldBaseType & {
385394
parsedValue: number | null;
386395
};
387396

397+
type ArticleParsedRefMetafield = MetafieldBaseType & {
398+
type: 'article_reference';
399+
parsedValue: Article | null;
400+
};
401+
388402
type PageParsedRefMetafield = MetafieldBaseType & {
389403
type: 'page_reference';
390404
parsedValue: Page | null;
@@ -410,6 +424,11 @@ type VariantParsedRefMetafield = MetafieldBaseType & {
410424
parsedValue: ProductVariant | null;
411425
};
412426

427+
type ArticleListParsedRefMetafield = MetafieldBaseType & {
428+
type: 'list.article_reference';
429+
parsedValue: Array<Article> | null;
430+
};
431+
413432
type CollectionListParsedRefMetafield = MetafieldBaseType & {
414433
type: 'list.collection_reference';
415434
parsedValue: Array<Collection> | null;

0 commit comments

Comments
 (0)