Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate options.values and use options.optionValues instead #2585

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/quick-hotels-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@shopify/hydrogen-react': patch
'skeleton': patch
'@shopify/hydrogen': patch
'@shopify/cli-hydrogen': patch
'@shopify/create-hydrogen': patch
---

Update to 2024-10 SFAPI
35 changes: 35 additions & 0 deletions .changeset/strange-zebras-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
'skeleton': patch
'@shopify/hydrogen': patch
'@shopify/cli-hydrogen': patch
'@shopify/create-hydrogen': patch
---

SFAPI update - Deprecate usages of `product.options.values` and use `product.options.optionValues` instead.

1. Update your product graphql query to use the new `optionValues` field.

```diff
const PRODUCT_FRAGMENT = `#graphql
fragment Product on Product {
id
title
options {
name
- values
+ optionValues {
+ name
+ }
}
```

2. Update your `<VariantSelector>` to use the new `optionValues` field.

```diff
<VariantSelector
handle={product.handle}
- options={product.options.filter((option) => option.values.length > 1)}
+ options={product.options.filter((option) => option.optionValues.length > 1)}
variants={variants}
>
```
2 changes: 1 addition & 1 deletion examples/b2b/app/components/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function ProductForm({
<div className="product-form">
<VariantSelector
handle={product.handle}
options={product.options.filter((option) => option.values.length > 1)}
options={product.options.filter((option) => option.optionValues.length > 1)}
variants={variants}
>
{({option}) => <ProductOptions key={option.name} option={option} />}
Expand Down
4 changes: 3 additions & 1 deletion examples/b2b/app/routes/products.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ const PRODUCT_FRAGMENT = `#graphql
description
options {
name
values
optionValues {
name
}
}
selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions, ignoreUnknownOptions: true, caseInsensitiveMatch: true) {
...ProductVariant
Expand Down
14 changes: 11 additions & 3 deletions examples/b2b/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,11 @@ export type ProductFragment = Pick<
StorefrontAPI.Product,
'id' | 'title' | 'vendor' | 'handle' | 'descriptionHtml' | 'description'
> & {
options: Array<Pick<StorefrontAPI.ProductOption, 'name' | 'values'>>;
options: Array<
Pick<StorefrontAPI.ProductOption, 'name'> & {
optionValues: Array<Pick<StorefrontAPI.ProductOptionValue, 'name'>>;
}
>;
selectedVariant?: StorefrontAPI.Maybe<
Pick<
StorefrontAPI.ProductVariant,
Expand Down Expand Up @@ -842,7 +846,11 @@ export type ProductQuery = {
StorefrontAPI.Product,
'id' | 'title' | 'vendor' | 'handle' | 'descriptionHtml' | 'description'
> & {
options: Array<Pick<StorefrontAPI.ProductOption, 'name' | 'values'>>;
options: Array<
Pick<StorefrontAPI.ProductOption, 'name'> & {
optionValues: Array<Pick<StorefrontAPI.ProductOptionValue, 'name'>>;
}
>;
selectedVariant?: StorefrontAPI.Maybe<
Pick<
StorefrontAPI.ProductVariant,
Expand Down Expand Up @@ -1296,7 +1304,7 @@ interface GeneratedQueryTypes {
return: PoliciesQuery;
variables: PoliciesQueryVariables;
};
'#graphql\n query Product(\n $country: CountryCode\n $buyer: BuyerInput\n $handle: String!\n $language: LanguageCode\n $selectedOptions: [SelectedOptionInput!]!\n ) @inContext(country: $country, language: $language, buyer: $buyer) {\n product(handle: $handle) {\n ...Product\n }\n }\n #graphql\n fragment Product on Product {\n id\n title\n vendor\n handle\n descriptionHtml\n description\n options {\n name\n values\n }\n selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions, ignoreUnknownOptions: true, caseInsensitiveMatch: true) {\n ...ProductVariant\n }\n variants(first: 1) {\n nodes {\n ...ProductVariant\n }\n }\n seo {\n description\n title\n }\n }\n #graphql\n fragment ProductVariant on ProductVariant {\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n id\n image {\n __typename\n id\n url\n altText\n width\n height\n }\n price {\n amount\n currencyCode\n }\n product {\n title\n handle\n }\n selectedOptions {\n name\n value\n }\n quantityRule {\n maximum\n minimum\n increment\n }\n quantityPriceBreaks(first: 5) {\n nodes {\n minimumQuantity\n price {\n amount\n currencyCode\n }\n }\n }\n sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n': {
'#graphql\n query Product(\n $country: CountryCode\n $buyer: BuyerInput\n $handle: String!\n $language: LanguageCode\n $selectedOptions: [SelectedOptionInput!]!\n ) @inContext(country: $country, language: $language, buyer: $buyer) {\n product(handle: $handle) {\n ...Product\n }\n }\n #graphql\n fragment Product on Product {\n id\n title\n vendor\n handle\n descriptionHtml\n description\n options {\n name\n optionValues {\n name\n }\n }\n selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions, ignoreUnknownOptions: true, caseInsensitiveMatch: true) {\n ...ProductVariant\n }\n variants(first: 1) {\n nodes {\n ...ProductVariant\n }\n }\n seo {\n description\n title\n }\n }\n #graphql\n fragment ProductVariant on ProductVariant {\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n id\n image {\n __typename\n id\n url\n altText\n width\n height\n }\n price {\n amount\n currencyCode\n }\n product {\n title\n handle\n }\n selectedOptions {\n name\n value\n }\n quantityRule {\n maximum\n minimum\n increment\n }\n quantityPriceBreaks(first: 5) {\n nodes {\n minimumQuantity\n price {\n amount\n currencyCode\n }\n }\n }\n sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n': {
return: ProductQuery;
variables: ProductQueryVariables;
};
Expand Down
2 changes: 1 addition & 1 deletion examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@remix-run/node": "^2.10.1",
"@remix-run/react": "^2.10.1",
"@remix-run/server-runtime": "^2.10.1",
"@shopify/hydrogen": "2024.7.8",
"@shopify/hydrogen": "2024.10.0",
"compression": "^1.7.4",
"cross-env": "^7.0.3",
"express": "^4.19.2",
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/hydrogen-react/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
customerAccountApiCustomScalars,
} from './src/codegen.helpers';

const SF_API_VERSION = '2024-07';
const CA_API_VERSION = '2024-07';
const SF_API_VERSION = '2024-10';
const CA_API_VERSION = '2024-10';

const storefrontAPISchema: CodegenConfig['schema'] = {
[`https://hydrogen-preview.myshopify.com/api/${SF_API_VERSION}/graphql.json`]:
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/customer-account.schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/hydrogen-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shopify/hydrogen-react",
"version": "2024.7.5",
"version": "2024.10.0",
"description": "React components, hooks, and utilities for creating custom Shopify storefronts",
"homepage": "https://github.com/Shopify/hydrogen/tree/main/packages/hydrogen-react",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/CartProvider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function CartComponent() {
const config: ShopifyProviderProps = {
storeDomain: 'hydrogen-preview.myshopify.com',
storefrontToken: '3b580e70970c4528da70c98e097c2fa0',
storefrontApiVersion: '2024-07',
storefrontApiVersion: '2024-10',
countryIsoCode: 'CA',
languageIsoCode: 'EN',
};
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/ShopPayButton2.example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function App() {
<ShopifyProvider
storeDomain="my-store"
storefrontToken="abc123"
storefrontApiVersion="2024-07"
storefrontApiVersion="2024-10"
countryIsoCode="CA"
languageIsoCode="EN"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/ShopPayButton2.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function App() {
<ShopifyProvider
storeDomain="my-store"
storefrontToken="abc123"
storefrontApiVersion="2024-07"
storefrontApiVersion="2024-10"
countryIsoCode="CA"
languageIsoCode="EN"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/ShopifyProvider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ export const Default = Template.bind({});
Default.args = {
storeDomain: 'notashop.myshopify.com',
storefrontToken: 'abc123',
version: '2024-07',
version: '2024-10',
};
16 changes: 8 additions & 8 deletions packages/hydrogen-react/src/ShopifyProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {PartialDeep} from 'type-fest';
const SHOPIFY_CONFIG: ShopifyProviderProps = {
storeDomain: 'https://notashop.myshopify.com',
storefrontToken: 'abc123',
storefrontApiVersion: '2024-07',
storefrontApiVersion: '2024-10',
countryIsoCode: 'CA',
languageIsoCode: 'EN',
};
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('<ShopifyProvider/>', () => {
});

expect(result.current.getStorefrontApiUrl()).toBe(
'https://notashop.myshopify.com/api/2024-07/graphql.json',
'https://notashop.myshopify.com/api/2024-10/graphql.json',
);
});

Expand Down Expand Up @@ -84,7 +84,7 @@ describe('<ShopifyProvider/>', () => {
).toEqual({
'X-SDK-Variant': 'hydrogen-react',
'X-SDK-Variant-Source': 'react',
'X-SDK-Version': '2024-07',
'X-SDK-Version': '2024-10',
'X-Shopify-Storefront-Access-Token': 'abc123',
'content-type': 'application/json',
});
Expand All @@ -110,7 +110,7 @@ describe('<ShopifyProvider/>', () => {
).toEqual({
'X-SDK-Variant': 'hydrogen-react',
'X-SDK-Variant-Source': 'react',
'X-SDK-Version': '2024-07',
'X-SDK-Version': '2024-10',
'X-Shopify-Storefront-Access-Token': 'newtoken',
'content-type': 'application/graphql',
});
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('<ShopifyProvider/>', () => {
});

expect(result.current.getStorefrontApiUrl()).toBe(
'https://notashop.myshopify.com/api/2024-07/graphql.json',
'https://notashop.myshopify.com/api/2024-10/graphql.json',
);
});

Expand All @@ -203,7 +203,7 @@ describe('<ShopifyProvider/>', () => {
result.current.getStorefrontApiUrl({
storeDomain: 'https://test.myshopify.com',
}),
).toBe('https://test.myshopify.com/api/2024-07/graphql.json');
).toBe('https://test.myshopify.com/api/2024-10/graphql.json');
});

it(`handles when a '/' is at the end of the url and doesn't add an extra one`, () => {
Expand All @@ -219,7 +219,7 @@ describe('<ShopifyProvider/>', () => {
});

expect(result.current.getStorefrontApiUrl()).toBe(
'https://notashop.myshopify.com/api/2024-07/graphql.json',
'https://notashop.myshopify.com/api/2024-10/graphql.json',
);
});
});
Expand All @@ -233,6 +233,6 @@ export function getShopifyConfig(
languageIsoCode: config.languageIsoCode ?? 'EN',
storeDomain: config.storeDomain ?? 'https://notashop.myshopify.io',
storefrontToken: config.storefrontToken ?? 'abc123',
storefrontApiVersion: config.storefrontApiVersion ?? '2024-07',
storefrontApiVersion: config.storefrontApiVersion ?? '2024-10',
};
}
Loading
Loading