diff --git a/.changeset/kind-chicken-roll.md b/.changeset/kind-chicken-roll.md new file mode 100644 index 00000000000..7b6d2df34d3 --- /dev/null +++ b/.changeset/kind-chicken-roll.md @@ -0,0 +1,10 @@ +--- +'@graphcommerce/magento-product-grouped': patch +'@graphcommerce/magento-cart-pickup': patch +'@graphcommerce/magento-cart-items': patch +'@graphcommerce/magento-graphcms': patch +'@graphcommerce/magento-product': patch +'@graphcommerce/magento-cart': patch +--- + +Create individual fragments for values with children to enhance readability and simplify type checking. diff --git a/examples/magento-graphcms/components/ProductListLayout/types.tsx b/examples/magento-graphcms/components/ProductListLayout/types.tsx index 67890e91349..75ddadd041b 100644 --- a/examples/magento-graphcms/components/ProductListLayout/types.tsx +++ b/examples/magento-graphcms/components/ProductListLayout/types.tsx @@ -1,4 +1,4 @@ -import { MenuQueryFragment } from '@graphcommerce/magento-category' +import { MenuQueryFragment, CategoryItemFragment } from '@graphcommerce/magento-category' import { CategoryDefaultFragment, FilterTypes, @@ -7,7 +7,6 @@ import { ProductListQuery, useProductList, } from '@graphcommerce/magento-product' -import { CategoryPageQuery } from '../../graphql/CategoryPage.gql' type BaseProps = MenuQueryFragment & ProductListQuery & @@ -25,8 +24,7 @@ type SearchLayoutProps = { type CategoryLayoutProps = { id: string title: string - category: CategoryDefaultFragment & - NonNullable['items']>[number] + category: CategoryDefaultFragment & CategoryItemFragment } type ProductListProps = ReturnType> diff --git a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx index 2474534cf53..175a177a517 100644 --- a/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx +++ b/examples/magento-graphcms/components/ProductView/AddProductsToCartView.tsx @@ -13,10 +13,10 @@ import { DownloadableProductOptions } from '@graphcommerce/magento-product-downl import { GroupedProducts } from '@graphcommerce/magento-product-grouped' import { isTypename } from '@graphcommerce/next-ui' import { Divider, Typography } from '@mui/material' -import { ProductPage2Query } from '../../graphql/ProductPage2.gql' +import { ProductPage2ItemFragment } from '../../graphql/ProductPage2Item.gql' export type AddProductsToCartViewProps = { - product: NonNullable['items']>[number]> + product: ProductPage2ItemFragment } export function AddProductsToCartView(props: AddProductsToCartViewProps) { diff --git a/examples/magento-graphcms/graphql/ProductPage2.graphql b/examples/magento-graphcms/graphql/ProductPage2.graphql index 408e80737bf..2983897338a 100644 --- a/examples/magento-graphcms/graphql/ProductPage2.graphql +++ b/examples/magento-graphcms/graphql/ProductPage2.graphql @@ -8,15 +8,7 @@ query ProductPage2( products(filter: { url_key: { eq: $urlKey } }) @inContext(context: $context) { ...ProductSpecs items { - __typename - uid - ...ProductCustomizable - ...ProductWeight - ...ProductPageItem - ...ConfigurableOptions - ...DownloadableProductOptions - ...BundleProductOptions - ...GroupedProduct + ...ProductPage2Item } } # Workaround for https://github.com/magento/magento2/issues/32427 diff --git a/examples/magento-graphcms/graphql/ProductPage2Item.graphql b/examples/magento-graphcms/graphql/ProductPage2Item.graphql new file mode 100644 index 00000000000..91facc93243 --- /dev/null +++ b/examples/magento-graphcms/graphql/ProductPage2Item.graphql @@ -0,0 +1,11 @@ +fragment ProductPage2Item on ProductInterface { + __typename + uid + ...ProductPageItem + ...ProductCustomizable + ...ProductWeight + ...ConfigurableOptions + ...DownloadableProductOptions + ...BundleProductOptions + ...GroupedProduct +} diff --git a/examples/magento-graphcms/pages/checkout/terms/[url].tsx b/examples/magento-graphcms/pages/checkout/terms/[url].tsx index 50c176d008e..c6a46752db2 100644 --- a/examples/magento-graphcms/pages/checkout/terms/[url].tsx +++ b/examples/magento-graphcms/pages/checkout/terms/[url].tsx @@ -1,5 +1,5 @@ import { PageOptions } from '@graphcommerce/framer-next-pages' -import { CartAgreementsDocument, CartAgreementsQuery } from '@graphcommerce/magento-cart' +import { CartAgreementFragment, CartAgreementsDocument } from '@graphcommerce/magento-cart' import { StoreConfigDocument } from '@graphcommerce/magento-store' import { GetStaticProps, PageMeta, LayoutOverlayHeader, LayoutTitle } from '@graphcommerce/next-ui' import { Container, Typography } from '@mui/material' @@ -7,7 +7,7 @@ import { GetStaticPaths } from 'next' import { LayoutOverlay, LayoutOverlayProps } from '../../../components' import { graphqlSsrClient, graphqlSharedClient } from '../../../lib/graphql/graphqlSsrClient' -type Props = { agreement: NonNullable[0]> } +type Props = { agreement: CartAgreementFragment } type RouteProps = { url: string } type GetPageStaticPaths = GetStaticPaths type GetPageStaticProps = GetStaticProps diff --git a/packages/magento-cart-items/Api/CartItems.graphql b/packages/magento-cart-items/Api/CartItems.graphql index 2e8057eaa64..4ad0ed903f6 100644 --- a/packages/magento-cart-items/Api/CartItems.graphql +++ b/packages/magento-cart-items/Api/CartItems.graphql @@ -1,8 +1,6 @@ fragment CartItems on Cart { id items { - uid - __typename ...CartItem } } diff --git a/packages/magento-cart-items/components/CartItems/CartItems.tsx b/packages/magento-cart-items/components/CartItems/CartItems.tsx index 09e6e36d698..e3c3cd3e3a2 100644 --- a/packages/magento-cart-items/components/CartItems/CartItems.tsx +++ b/packages/magento-cart-items/components/CartItems/CartItems.tsx @@ -1,8 +1,9 @@ import { RenderType, TypeRenderer } from '@graphcommerce/next-ui' import { Box } from '@mui/material' +import { CartItemFragment } from '../../Api/CartItem.gql' import { CartItemsFragment } from '../../Api/CartItems.gql' -export type CartItemRenderer = TypeRenderer[0]>> +export type CartItemRenderer = TypeRenderer export type CartProps = { renderer: CartItemRenderer } & CartItemsFragment diff --git a/packages/magento-cart-pickup/components/PickupLocationActionCard.tsx b/packages/magento-cart-pickup/components/PickupLocationActionCard.tsx index 7bca65e54c8..ccfba008962 100644 --- a/packages/magento-cart-pickup/components/PickupLocationActionCard.tsx +++ b/packages/magento-cart-pickup/components/PickupLocationActionCard.tsx @@ -1,11 +1,9 @@ import { ActionCard, ActionCardItemRenderProps } from '@graphcommerce/next-ui' import { Trans } from '@lingui/react' import { Box, Button } from '@mui/material' -import { GetPickupLocationsForProductsQuery } from '../graphql/GetPickupLocationsForProducts.gql' +import { PickupLocationItemFragment } from '../graphql/PickupLocationItem.gql' -export type Location = NonNullable< - NonNullable['items']>[number] -> +export type Location = PickupLocationItemFragment export function PickupLocationActionCard(props: ActionCardItemRenderProps) { const { onReset, name, contact_name, street, postcode, city, description, ...cardProps } = props diff --git a/packages/magento-cart-pickup/graphql/GetPickupLocationsForProducts.graphql b/packages/magento-cart-pickup/graphql/GetPickupLocationsForProducts.graphql index 31171beec31..a53e0d8f113 100644 --- a/packages/magento-cart-pickup/graphql/GetPickupLocationsForProducts.graphql +++ b/packages/magento-cart-pickup/graphql/GetPickupLocationsForProducts.graphql @@ -12,21 +12,7 @@ query GetPickupLocationsForProducts( currentPage: $currentPage ) { items { - city - pickup_location_code - contact_name - country_id - description - email - fax - latitude - longitude - name - phone - postcode - region - region_id - street + ...PickupLocationItem } } } diff --git a/packages/magento-cart-pickup/graphql/PickupLocationItem.graphql b/packages/magento-cart-pickup/graphql/PickupLocationItem.graphql new file mode 100644 index 00000000000..f6eed42d16c --- /dev/null +++ b/packages/magento-cart-pickup/graphql/PickupLocationItem.graphql @@ -0,0 +1,17 @@ +fragment PickupLocationItem on PickupLocation { + city + pickup_location_code + contact_name + country_id + description + email + fax + latitude + longitude + name + phone + postcode + region + region_id + street +} diff --git a/packages/magento-cart/components/CartAgreementsForm/CartAgreement.graphql b/packages/magento-cart/components/CartAgreementsForm/CartAgreement.graphql new file mode 100644 index 00000000000..3955c90ecc3 --- /dev/null +++ b/packages/magento-cart/components/CartAgreementsForm/CartAgreement.graphql @@ -0,0 +1,9 @@ +fragment CartAgreement on CheckoutAgreement { + agreement_id + checkbox_text + content + content_height + is_html + mode + name +} diff --git a/packages/magento-cart/components/CartAgreementsForm/CartAgreements.graphql b/packages/magento-cart/components/CartAgreementsForm/CartAgreements.graphql index 772ed445d1a..4b6e93b5a2d 100644 --- a/packages/magento-cart/components/CartAgreementsForm/CartAgreements.graphql +++ b/packages/magento-cart/components/CartAgreementsForm/CartAgreements.graphql @@ -1,11 +1,5 @@ query CartAgreements { checkoutAgreements { - agreement_id - checkbox_text - content - content_height - is_html - mode - name + ...CartAgreement } } diff --git a/packages/magento-cart/components/index.ts b/packages/magento-cart/components/index.ts index cf89a0e7c13..556bf7e93a1 100644 --- a/packages/magento-cart/components/index.ts +++ b/packages/magento-cart/components/index.ts @@ -2,6 +2,7 @@ export * from './ApolloCartError' export * from './CartAdded' export * from './CartAddressMultiLine/CartAddressMultiLine' export * from './CartAddressSingleLine/CartAddressSingleLine' +export * from './CartAgreementsForm/CartAgreement.gql' export * from './CartAgreementsForm/CartAgreements.gql' export * from './CartAgreementsForm/CartAgreementsForm' export * from './CartFab/CartFab' diff --git a/packages/magento-category/index.ts b/packages/magento-category/index.ts index 03d63c9c521..d5c1ccd54fd 100644 --- a/packages/magento-category/index.ts +++ b/packages/magento-category/index.ts @@ -10,7 +10,9 @@ export * from './utils/magentoMenuToNavigation' export * from './utils/findParentBreadcrumbItem' export * from './queries/getCategoryStaticPaths' export * from './components/CategoryBreadcrumb' +export * from './queries/CategoryItem.gql' export * from './queries/CategoryQueryFragment.gql' export * from './queries/MenuQueryFragment.gql' +export * from './queries/MenuQueryCategoryItem.gql' export * from './queries/NavigationItem.gql' export * from './utils/useCategoryTree' diff --git a/packages/magento-category/queries/CategoryItem.graphql b/packages/magento-category/queries/CategoryItem.graphql new file mode 100644 index 00000000000..10c8b8a6572 --- /dev/null +++ b/packages/magento-category/queries/CategoryItem.graphql @@ -0,0 +1,9 @@ +fragment CategoryItem on CategoryTree { + uid + ...CategoryDefault + ...CategoryBreadcrumb + ...CategoryDescription + ...CategoryChildren + ...CategoryMeta + ...CategoryHeroNav +} diff --git a/packages/magento-category/queries/CategoryQueryFragment.graphql b/packages/magento-category/queries/CategoryQueryFragment.graphql index 5053e744f19..d5edd3664cd 100644 --- a/packages/magento-category/queries/CategoryQueryFragment.graphql +++ b/packages/magento-category/queries/CategoryQueryFragment.graphql @@ -1,13 +1,7 @@ fragment CategoryQueryFragment on Query { categories(filters: { url_path: { eq: $url } }) { items { - uid - ...CategoryDefault - ...CategoryBreadcrumb - ...CategoryDescription - ...CategoryChildren - ...CategoryMeta - ...CategoryHeroNav + ...CategoryItem } } } diff --git a/packages/magento-category/queries/MenuQueryCategoryItem.graphql b/packages/magento-category/queries/MenuQueryCategoryItem.graphql new file mode 100644 index 00000000000..bb99ceefb38 --- /dev/null +++ b/packages/magento-category/queries/MenuQueryCategoryItem.graphql @@ -0,0 +1,16 @@ +fragment MenuQueryCategoryItem on CategoryTree { + uid + ...NavigationItem + children { + uid + ...NavigationItem + children { + uid + ...NavigationItem + children { + uid + ...NavigationItem + } + } + } +} diff --git a/packages/magento-category/queries/MenuQueryFragment.graphql b/packages/magento-category/queries/MenuQueryFragment.graphql index 0d018d1bd76..9e8cf504492 100644 --- a/packages/magento-category/queries/MenuQueryFragment.graphql +++ b/packages/magento-category/queries/MenuQueryFragment.graphql @@ -1,20 +1,7 @@ fragment MenuQueryFragment on Query { menu: categories { items { - uid - ...NavigationItem - children { - uid - ...NavigationItem - children { - uid - ...NavigationItem - children { - uid - ...NavigationItem - } - } - } + ...MenuQueryCategoryItem } } } diff --git a/packages/magento-category/utils/magentoMenuToNavigation.tsx b/packages/magento-category/utils/magentoMenuToNavigation.tsx index 23cf78e14db..3e4f48779f7 100644 --- a/packages/magento-category/utils/magentoMenuToNavigation.tsx +++ b/packages/magento-category/utils/magentoMenuToNavigation.tsx @@ -6,15 +6,14 @@ import { nonNullable, } from '@graphcommerce/next-ui' import { i18n } from '@lingui/core' +import { MenuQueryCategoryItemFragment } from '../queries/MenuQueryCategoryItem.gql' import { MenuQueryFragment } from '../queries/MenuQueryFragment.gql' import { NavigationItemFragment } from '../queries/NavigationItem.gql' -type Item = NonNullable['items']>[0]> - export type MagentoNavigationItemProps = NavigationItemFragment function categoryToNav( - props: Item | null | undefined, + props: MenuQueryCategoryItemFragment | null | undefined, Component?: React.ComponentType, ): NavigationNode | undefined { if (!props) return undefined diff --git a/packages/magento-product-grouped/GroupedProduct.graphql b/packages/magento-product-grouped/GroupedProduct.graphql index be84ee8039a..9c242b3f2b7 100644 --- a/packages/magento-product-grouped/GroupedProduct.graphql +++ b/packages/magento-product-grouped/GroupedProduct.graphql @@ -1,4 +1,6 @@ fragment GroupedProduct on GroupedProduct { + __typename + uid items { position qty diff --git a/packages/magento-product-grouped/GroupedProducts/GroupedProducts.tsx b/packages/magento-product-grouped/GroupedProducts/GroupedProducts.tsx index 2e78b15c002..22d3fccb34e 100644 --- a/packages/magento-product-grouped/GroupedProducts/GroupedProducts.tsx +++ b/packages/magento-product-grouped/GroupedProducts/GroupedProducts.tsx @@ -1,10 +1,10 @@ import { ActionCardLayout, filterNonNullableKeys } from '@graphcommerce/next-ui' import { useMemo } from 'react' -import { ProductPageGroupedQueryFragment } from '../ProductPageGroupedQueryFragment.gql' +import { GroupedProductFragment } from '../GroupedProduct.gql' import { GroupedProductActionCard } from './GroupedProductActionCard' type GroupedProductsProps = { - product: NonNullable['items']>[0] + product: GroupedProductFragment } export function GroupedProducts(props: GroupedProductsProps) { diff --git a/packages/magento-product-grouped/ProductPageGroupedQueryFragment.graphql b/packages/magento-product-grouped/ProductPageGroupedQueryFragment.graphql index 8fef29bc86f..0dcf99934bb 100644 --- a/packages/magento-product-grouped/ProductPageGroupedQueryFragment.graphql +++ b/packages/magento-product-grouped/ProductPageGroupedQueryFragment.graphql @@ -1,8 +1,6 @@ fragment ProductPageGroupedQueryFragment on Query { typeProducts: products(filter: { url_key: { eq: $urlKey } }) { items { - __typename - uid ...GroupedProduct } } diff --git a/packages/magento-product/components/ProductCustomizable/CustomizableAreaOption.tsx b/packages/magento-product/components/ProductCustomizable/CustomizableAreaOption.tsx index e005d6c55f5..ee1025997a2 100644 --- a/packages/magento-product/components/ProductCustomizable/CustomizableAreaOption.tsx +++ b/packages/magento-product/components/ProductCustomizable/CustomizableAreaOption.tsx @@ -6,10 +6,10 @@ import { i18n } from '@lingui/core' import { Box } from '@mui/material' import React from 'react' import { useFormAddProductsToCart } from '../AddProductsToCart' -import { ProductCustomizableFragment } from './ProductCustomizable.gql' +import { CustomizableOptionFragment } from './CustomizableOption.gql' export type OptionTypeRenderer = TypeRenderer< - NonNullable[number]> & { + CustomizableOptionFragment & { optionIndex: number index: number currency: CurrencyEnum diff --git a/packages/magento-product/components/ProductCustomizable/CustomizableOption.graphql b/packages/magento-product/components/ProductCustomizable/CustomizableOption.graphql index 49937a3f5ea..788c256225b 100644 --- a/packages/magento-product/components/ProductCustomizable/CustomizableOption.graphql +++ b/packages/magento-product/components/ProductCustomizable/CustomizableOption.graphql @@ -1,6 +1,15 @@ fragment CustomizableOption on CustomizableOptionInterface { + __typename uid required sort_order title + ...CustomizableAreaOption + ...CustomizableCheckboxOption + ...CustomizableDateOption + ...CustomizableDropDownOption + ...CustomizableMultipleOption + ...CustomizableFieldOption + ...CustomizableFileOption + ...CustomizableRadioOption } diff --git a/packages/magento-product/components/ProductCustomizable/ProductCustomizable.graphql b/packages/magento-product/components/ProductCustomizable/ProductCustomizable.graphql index 105c64201f9..16b7f190eb8 100644 --- a/packages/magento-product/components/ProductCustomizable/ProductCustomizable.graphql +++ b/packages/magento-product/components/ProductCustomizable/ProductCustomizable.graphql @@ -1,15 +1,5 @@ fragment ProductCustomizable on CustomizableProductInterface { options { - uid - __typename ...CustomizableOption - ...CustomizableAreaOption - ...CustomizableCheckboxOption - ...CustomizableDateOption - ...CustomizableDropDownOption - ...CustomizableMultipleOption - ...CustomizableFieldOption - ...CustomizableFileOption - ...CustomizableRadioOption } } diff --git a/packages/magento-product/components/ProductFiltersPro/ProductFiltersProAggregations.tsx b/packages/magento-product/components/ProductFiltersPro/ProductFiltersProAggregations.tsx index 65c839e9755..99c9c27a50a 100644 --- a/packages/magento-product/components/ProductFiltersPro/ProductFiltersProAggregations.tsx +++ b/packages/magento-product/components/ProductFiltersPro/ProductFiltersProAggregations.tsx @@ -1,5 +1,5 @@ import { AttributeFrontendInputEnum } from '@graphcommerce/graphql-mesh' -import { ProductListFiltersFragment } from '../ProductListFilters/ProductListFilters.gql' +import { ProductListAggregationFragment } from '../ProductListFilters' import { ProductFilterEqualChip } from './ProductFilterEqualChip' import { ProductFilterEqualSection } from './ProductFilterEqualSection' import { ProductFilterRangeChip } from './ProductFilterRangeChip' @@ -9,7 +9,7 @@ import { excludeCategory } from './activeAggregations' import { applyAggregationCount } from './applyAggregationCount' export type FilterProps = { - aggregation: NonNullable[number]> + aggregation: ProductListAggregationFragment } export type FilterRenderer = Record> diff --git a/packages/magento-product/components/ProductListFilters/ProductListAggregation.graphql b/packages/magento-product/components/ProductListFilters/ProductListAggregation.graphql new file mode 100644 index 00000000000..205b8bd3c3f --- /dev/null +++ b/packages/magento-product/components/ProductListFilters/ProductListAggregation.graphql @@ -0,0 +1,12 @@ +fragment ProductListAggregation on Aggregation { + __typename + label + attribute_code + count + options { + __typename + label + value + count + } +} diff --git a/packages/magento-product/components/ProductListFilters/ProductListFilters.graphql b/packages/magento-product/components/ProductListFilters/ProductListFilters.graphql index fe8147c2923..18412b297ae 100644 --- a/packages/magento-product/components/ProductListFilters/ProductListFilters.graphql +++ b/packages/magento-product/components/ProductListFilters/ProductListFilters.graphql @@ -1,14 +1,5 @@ fragment ProductListFilters on Products { aggregations(filter: { category: { includeDirectChildrenOnly: true } }) { - __typename - label - attribute_code - count - options { - __typename - label - value - count - } + ...ProductListAggregation } } diff --git a/packages/magento-product/components/ProductListFilters/index.ts b/packages/magento-product/components/ProductListFilters/index.ts index 144d19d374f..19a24d5fd82 100644 --- a/packages/magento-product/components/ProductListFilters/index.ts +++ b/packages/magento-product/components/ProductListFilters/index.ts @@ -1,2 +1,3 @@ export * from './ProductFilters.gql' +export * from './ProductListAggregation.gql' export * from './ProductListFilters'