Skip to content

Commit

Permalink
Removed quantityAvailable from template PDP graphql query. (#1236)
Browse files Browse the repository at this point in the history
Removed quantityAvailable from template PDP graphql query.
  • Loading branch information
abecciu authored Aug 17, 2023
1 parent aac685b commit e536ae0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/wild-brooms-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/cli-hydrogen': patch
'@shopify/create-hydrogen': patch
---

Removed quantityAvailable field from skeleton PDP graphql query so that it works with default Storefront API permissions.
9 changes: 6 additions & 3 deletions templates/skeleton/app/routes/products.$handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
getSelectedProductOptions,
CartForm,
} from '@shopify/hydrogen';
import type {CartLineInput} from '@shopify/hydrogen/storefront-api-types';
import type {
CartLineInput,
SelectedOption,
} from '@shopify/hydrogen/storefront-api-types';
import {getVariantUrl} from '~/utils';

export const meta: V2_MetaFunction = ({data}) => {
Expand Down Expand Up @@ -67,7 +70,8 @@ export async function loader({params, request, context}: LoaderArgs) {
const firstVariant = product.variants.nodes[0];
const firstVariantIsDefault = Boolean(
firstVariant.selectedOptions.find(
(option) => option.name === 'Title' && option.value === 'Default Title',
(option: SelectedOption) =>
option.name === 'Title' && option.value === 'Default Title',
),
);

Expand Down Expand Up @@ -341,7 +345,6 @@ const PRODUCT_VARIANT_FRAGMENT = `#graphql
title
handle
}
quantityAvailable
selectedOptions {
name
value
Expand Down
18 changes: 9 additions & 9 deletions templates/skeleton/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ export type PoliciesQuery = {

export type ProductVariantFragment = Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand All @@ -1377,7 +1377,7 @@ export type ProductFragment = Pick<
selectedVariant?: StorefrontAPI.Maybe<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand All @@ -1402,7 +1402,7 @@ export type ProductFragment = Pick<
nodes: Array<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand Down Expand Up @@ -1446,7 +1446,7 @@ export type ProductQuery = {
selectedVariant?: StorefrontAPI.Maybe<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand All @@ -1471,7 +1471,7 @@ export type ProductQuery = {
nodes: Array<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand Down Expand Up @@ -1503,7 +1503,7 @@ export type ProductVariantsFragment = {
nodes: Array<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand Down Expand Up @@ -1539,7 +1539,7 @@ export type ProductVariantsQuery = {
nodes: Array<
Pick<
StorefrontAPI.ProductVariant,
'availableForSale' | 'id' | 'quantityAvailable' | 'sku' | 'title'
'availableForSale' | 'id' | 'sku' | 'title'
> & {
compareAtPrice?: StorefrontAPI.Maybe<
Pick<StorefrontAPI.MoneyV2, 'amount' | 'currencyCode'>
Expand Down Expand Up @@ -1839,11 +1839,11 @@ interface GeneratedQueryTypes {
return: PoliciesQuery;
variables: PoliciesQueryVariables;
};
'#graphql\n query Product(\n $country: CountryCode\n $handle: String!\n $language: LanguageCode\n $selectedOptions: [SelectedOptionInput!]!\n ) @inContext(country: $country, language: $language) {\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) {\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 quantityAvailable\n selectedOptions {\n name\n value\n }\n sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n': {
'#graphql\n query Product(\n $country: CountryCode\n $handle: String!\n $language: LanguageCode\n $selectedOptions: [SelectedOptionInput!]!\n ) @inContext(country: $country, language: $language) {\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) {\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 sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n': {
return: ProductQuery;
variables: ProductQueryVariables;
};
'#graphql\n #graphql\n fragment ProductVariants on Product {\n variants(first: 250) {\n nodes {\n ...ProductVariant\n }\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 quantityAvailable\n selectedOptions {\n name\n value\n }\n sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n query ProductVariants(\n $country: CountryCode\n $language: LanguageCode\n $handle: String!\n ) @inContext(country: $country, language: $language) {\n product(handle: $handle) {\n ...ProductVariants\n }\n }\n': {
'#graphql\n #graphql\n fragment ProductVariants on Product {\n variants(first: 250) {\n nodes {\n ...ProductVariant\n }\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 sku\n title\n unitPrice {\n amount\n currencyCode\n }\n }\n\n\n query ProductVariants(\n $country: CountryCode\n $language: LanguageCode\n $handle: String!\n ) @inContext(country: $country, language: $language) {\n product(handle: $handle) {\n ...ProductVariants\n }\n }\n': {
return: ProductVariantsQuery;
variables: ProductVariantsQueryVariables;
};
Expand Down

0 comments on commit e536ae0

Please sign in to comment.