Skip to content

Commit 9e7aac5

Browse files
committed
feat: add languageCode and countryCode to GetShopInfo query and loader props
1 parent a4d3515 commit 9e7aac5

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

shopify/loaders/shop.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import { AppContext } from "../mod.ts";
22
import { GetShopInfo } from "../utils/storefront/queries.ts";
33
import {
4+
CountryCode,
5+
LanguageCode,
46
Shop,
57
ShopMetafieldsArgs,
68
} from "../utils/storefront/storefront.graphql.gen.ts";
7-
import { Metafield } from "../utils/types.ts";
9+
import { LanguageContextArgs, Metafield } from "../utils/types.ts";
810

911
export interface Props {
1012
/**
1113
* @title Metafields
1214
* @description search for metafields
1315
*/
1416
metafields?: Metafield[];
17+
/**
18+
* @title Language Code
19+
* @description Language code for the storefront API
20+
* @example "EN" for English, "FR" for French, etc.
21+
*/
22+
languageCode?: LanguageCode;
23+
/**
24+
* @title Country Code
25+
* @description Country code for the storefront API
26+
* @example "US" for United States, "FR" for France, etc.
27+
*/
28+
countryCode?: CountryCode;
1529
}
1630

1731
export const defaultVisibility = "private";
@@ -22,10 +36,13 @@ const loader = async (
2236
ctx: AppContext,
2337
): Promise<Shop> => {
2438
const { storefront } = ctx;
25-
const { metafields = [] } = props;
39+
const { metafields = [], languageCode = "PT", countryCode = "BR" } = props;
2640

27-
const shop = await storefront.query<{ shop: Shop }, ShopMetafieldsArgs>({
28-
variables: { identifiers: metafields },
41+
const shop = await storefront.query<
42+
{ shop: Shop },
43+
ShopMetafieldsArgs & LanguageContextArgs
44+
>({
45+
variables: { identifiers: metafields, languageCode, countryCode },
2946
...GetShopInfo,
3047
}).then((data) => data.shop);
3148

shopify/utils/storefront/queries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ export const ProductRecommendations = {
405405
};
406406

407407
export const GetShopInfo = {
408-
query: gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!) {
408+
query:
409+
gql`query GetShopInfo($identifiers: [HasMetafieldsIdentifier!]!, $languageCode: LanguageCode, $countryCode: CountryCode) @inContext(language: $languageCode, country: $countryCode) {
409410
shop {
410411
name
411412
description

0 commit comments

Comments
 (0)