Skip to content

Commit

Permalink
Renamed useInContextQuery to usePrivateQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
paales committed Dec 17, 2024
1 parent f6e7d70 commit 5dfd3b2
Show file tree
Hide file tree
Showing 34 changed files with 184 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .changeset/brown-tools-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphcommerce/graphql': patch
---

The `<InContextMask />` component now only warns when a block is rendered during the initial SSR render.
The `<PrivateQueryMask />` component now only warns when a block is rendered during the initial SSR render.
2 changes: 1 addition & 1 deletion .changeset/odd-mails-yell.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphcommerce/magento-customer': patch
---

Remove the inContext directive from the query before sending to the server
Remove the privateContext directive from the query before sending to the server
9 changes: 9 additions & 0 deletions .changeset/shiny-pumpkins-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@graphcommerce/algolia-personalization': patch
'@graphcommerce/magento-customer': patch
'@graphcommerce/magento-product': patch
'@graphcommerce/magento-search': patch
'@graphcommerce/graphql': patch
---

Renamed useInContextQuery to usePrivateQuery
2 changes: 1 addition & 1 deletion .changeset/thin-teachers-try.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@graphcommerce/graphql': patch
---

When a `useInContextQuery` is called, only execute when there is no `InContextMaskContext` defined above.
When a `usePrivateQuery` is called, only execute when there is no `PrivateQueryMaskContext` defined above.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InContextMaskProvider, useInContextQuery } from '@graphcommerce/graphql'
import { PrivateQueryMaskProvider, usePrivateQuery } from '@graphcommerce/graphql'
import { ProductListDocument, ProductListItemsFragment } from '@graphcommerce/magento-product'
import { ProductSpecsFragment } from '@graphcommerce/magento-product/components/ProductSpecs/ProductSpecs.gql'
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
Expand Down Expand Up @@ -41,7 +41,7 @@ export function RowProduct(props: RowProductProps) {
const mergedRenderer = { ...defaultRenderer, ...renderer } as VariantRenderer

const urlKeys = filterNonNullableKeys(items).map((item) => item.url_key)
const scoped = useInContextQuery(
const scoped = usePrivateQuery(
ProductListDocument,
{ variables: { onlyItems: true, filters: { url_key: { in: urlKeys } } } },
{ products: { items } },
Expand All @@ -58,8 +58,8 @@ export function RowProduct(props: RowProductProps) {
})

return (
<InContextMaskProvider mask={scoped.mask}>
<PrivateQueryMaskProvider mask={scoped.mask}>
<RenderType {...rest} {...products} />
</InContextMaskProvider>
</PrivateQueryMaskProvider>
)
}
7 changes: 4 additions & 3 deletions examples/magento-graphcms/graphql/ProductPage2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ query ProductPage2(
$urlKey: String!
$reviewPageSize: Int = 3
$reviewPage: Int = 1
$context: InContextInput
$context: PrivateContext
$useCustomAttributes: Boolean = false
) {
products(filter: { url_key: { eq: $urlKey } }) @inContext(context: $context) {
products(filter: { url_key: { eq: $urlKey } }) @privateContext(context: $context) {
...ProductSpecs
items {
__typename
Expand All @@ -20,7 +20,8 @@ query ProductPage2(
}
}
# Workaround for https://github.com/magento/magento2/issues/32427
relatedUpsells: products(filter: { url_key: { eq: $urlKey } }) @inContext(context: $context) {
relatedUpsells: products(filter: { url_key: { eq: $urlKey } })
@privateContext(context: $context) {
items {
uid
...UpsellProducts
Expand Down
7 changes: 3 additions & 4 deletions examples/magento-graphcms/pages/[...url].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import { cacheFirst, flushMeasurePerf, InContextMaskProvider } from '@graphcommerce/graphql'
import { cacheFirst, flushMeasurePerf, PrivateQueryMaskProvider } from '@graphcommerce/graphql'
import { Asset, hygraphPageContent, HygraphPagesQuery } from '@graphcommerce/hygraph-ui'
import {
appendSiblingsAsChildren,
Expand Down Expand Up @@ -69,9 +69,8 @@ function CategoryPage(props: CategoryProps) {
const page = pages?.[0]
const isCategory = params && category && products?.items

console.log(page?.asset)
return (
<InContextMaskProvider mask={productList.mask}>
<PrivateQueryMaskProvider mask={productList.mask}>
<CategoryMeta
params={params}
title={page?.metaTitle}
Expand Down Expand Up @@ -161,7 +160,7 @@ function CategoryPage(props: CategoryProps) {
}}
/>
)}
</InContextMaskProvider>
</PrivateQueryMaskProvider>
)
}

Expand Down
10 changes: 5 additions & 5 deletions examples/magento-graphcms/pages/p/[url].tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import {
cacheFirst,
InContextMaskProvider,
PrivateQueryMaskProvider,
mergeDeep,
useInContextQuery,
usePrivateQuery,
} from '@graphcommerce/graphql'
import { hygraphPageContent, HygraphPagesQuery } from '@graphcommerce/hygraph-ui'
import {
Expand Down Expand Up @@ -60,7 +60,7 @@ type GetPageStaticProps = GetStaticProps<LayoutNavigationProps, Props, RouteProp
function ProductPage(props: Props) {
const { usps, sidebarUsps, pages, defaultValues, urlKey } = props

const scopedQuery = useInContextQuery(
const scopedQuery = usePrivateQuery(
ProductPage2Document,
{ variables: { urlKey, useCustomAttributes: import.meta.graphCommerce.magentoVersion >= 247 } },
props,
Expand All @@ -75,7 +75,7 @@ function ProductPage(props: Props) {
if (!product?.sku || !product.url_key) return null

return (
<InContextMaskProvider mask={scopedQuery.mask}>
<PrivateQueryMaskProvider mask={scopedQuery.mask}>
<AddProductsToCartForm key={product.uid} defaultValues={defaultValues}>
<LayoutHeader floatingMd hideMd={import.meta.graphCommerce.breadcrumbs}>
<LayoutTitle size='small' component='span'>
Expand Down Expand Up @@ -178,7 +178,7 @@ function ProductPage(props: Props) {
productListRenderer={productListRenderer}
sx={(theme) => ({ mb: theme.spacings.xxl })}
/>
</InContextMaskProvider>
</PrivateQueryMaskProvider>
)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/magento-graphcms/pages/search/[[...url]].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PageOptions } from '@graphcommerce/framer-next-pages'
import { InContextMaskProvider, cacheFirst, flushMeasurePerf } from '@graphcommerce/graphql'
import { PrivateQueryMaskProvider, cacheFirst, flushMeasurePerf } from '@graphcommerce/graphql'
import { MenuQueryFragment } from '@graphcommerce/magento-category'
import {
ProductListDocument,
Expand Down Expand Up @@ -61,7 +61,7 @@ function SearchResultPage(props: SearchResultProps) {
<ProductFiltersProSearchField size='small' formControl={{ sx: { width: '81vw' } }} />
</LayoutHeader>

<InContextMaskProvider mask={productList.mask}>
<PrivateQueryMaskProvider mask={productList.mask}>
{import.meta.graphCommerce.productFiltersPro &&
import.meta.graphCommerce.productFiltersLayout === 'SIDEBAR' && (
<ProductListLayoutSidebar {...productList} menu={menu} />
Expand All @@ -73,7 +73,7 @@ function SearchResultPage(props: SearchResultProps) {
{!import.meta.graphCommerce.productFiltersPro && (
<ProductListLayoutClassic {...productList} menu={menu} />
)}
</InContextMaskProvider>
</PrivateQueryMaskProvider>
</>
)
}
Expand Down
7 changes: 4 additions & 3 deletions examples/magento-open-source/graphql/ProductPage2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ query ProductPage2(
$urlKey: String!
$reviewPageSize: Int = 3
$reviewPage: Int = 1
$context: InContextInput
$context: PrivateContext
$useCustomAttributes: Boolean = false
) {
products(filter: { url_key: { eq: $urlKey } }) @inContext(context: $context) {
products(filter: { url_key: { eq: $urlKey } }) @privateContext(context: $context) {
...ProductSpecs
items {
__typename
Expand All @@ -20,7 +20,8 @@ query ProductPage2(
}
}
# Workaround for https://github.com/magento/magento2/issues/32427
relatedUpsells: products(filter: { url_key: { eq: $urlKey } }) @inContext(context: $context) {
relatedUpsells: products(filter: { url_key: { eq: $urlKey } })
@privateContext(context: $context) {
items {
uid
...UpsellProducts
Expand Down
6 changes: 3 additions & 3 deletions examples/magento-open-source/pages/[...url].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PageOptions } from '@graphcommerce/framer-next-pages'
import { cacheFirst, flushMeasurePerf, InContextMaskProvider } from '@graphcommerce/graphql'
import { cacheFirst, flushMeasurePerf, PrivateQueryMaskProvider } from '@graphcommerce/graphql'
import {
appendSiblingsAsChildren,
CategoryBreadcrumbs,
Expand Down Expand Up @@ -63,7 +63,7 @@ function CategoryPage(props: CategoryProps) {
const isCategory = params && category && products?.items

return (
<InContextMaskProvider mask={productList.mask}>
<PrivateQueryMaskProvider mask={productList.mask}>
<CategoryMeta params={params} {...category} />
<LayoutHeader floatingMd hideMd={import.meta.graphCommerce.breadcrumbs}>
<LayoutTitle size='small' component='span'>
Expand Down Expand Up @@ -124,7 +124,7 @@ function CategoryPage(props: CategoryProps) {
)}
</>
)}
</InContextMaskProvider>
</PrivateQueryMaskProvider>
)
}

Expand Down
24 changes: 12 additions & 12 deletions examples/magento-open-source/pages/p/[url].tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import type { PageOptions } from '@graphcommerce/framer-next-pages'
import {
InContextMaskProvider,
cacheFirst,
mergeDeep,
useInContextQuery,
PrivateQueryMaskProvider,
usePrivateQuery,
} from '@graphcommerce/graphql'
import type { AddProductsToCartFormProps } from '@graphcommerce/magento-product'
import {
AddProductsToCartButton,
AddProductsToCartForm,
getProductStaticPaths,
jsonLdProduct,
jsonLdProductOffer,
ProductPageAddToCartActionsRow,
ProductPageBreadcrumbs,
productPageCategory,
ProductPageDescription,
ProductPageGallery,
ProductPageJsonLd,
Expand All @@ -19,21 +23,17 @@ import {
ProductScroller,
ProductShortDescription,
ProductSpecs,
getProductStaticPaths,
jsonLdProduct,
jsonLdProductOffer,
productPageCategory,
} from '@graphcommerce/magento-product'
import { defaultConfigurableOptionsSelection } from '@graphcommerce/magento-product-configurable'
import { RecentlyViewedProducts } from '@graphcommerce/magento-recently-viewed-products'
import { ProductReviewChip, jsonLdProductReview } from '@graphcommerce/magento-review'
import { Money, StoreConfigDocument, redirectOrNotFound } from '@graphcommerce/magento-store'
import { jsonLdProductReview, ProductReviewChip } from '@graphcommerce/magento-review'
import { Money, redirectOrNotFound, StoreConfigDocument } from '@graphcommerce/magento-store'
import { ProductWishlistChipDetail } from '@graphcommerce/magento-wishlist'
import type { GetStaticProps } from '@graphcommerce/next-ui'
import {
isTypename,
LayoutHeader,
LayoutTitle,
isTypename,
nonNullable,
responsiveVal,
} from '@graphcommerce/next-ui'
Expand All @@ -59,7 +59,7 @@ type GetPageStaticProps = GetStaticProps<LayoutNavigationProps, Props, RouteProp
function ProductPage(props: Props) {
const { defaultValues, urlKey } = props

const scopedQuery = useInContextQuery(
const scopedQuery = usePrivateQuery(
ProductPage2Document,
{ variables: { urlKey, useCustomAttributes: import.meta.graphCommerce.magentoVersion >= 247 } },
props,
Expand All @@ -74,7 +74,7 @@ function ProductPage(props: Props) {
if (!product?.sku || !product.url_key) return null

return (
<InContextMaskProvider mask={scopedQuery.mask}>
<PrivateQueryMaskProvider mask={scopedQuery.mask}>
<AddProductsToCartForm key={product.uid} defaultValues={defaultValues}>
<LayoutHeader floatingMd hideMd={import.meta.graphCommerce.breadcrumbs}>
<LayoutTitle size='small' component='span'>
Expand Down Expand Up @@ -192,7 +192,7 @@ function ProductPage(props: Props) {
}}
sx={(theme) => ({ mb: theme.spacings.xxl })}
/>
</InContextMaskProvider>
</PrivateQueryMaskProvider>
)
}

Expand Down
10 changes: 5 additions & 5 deletions examples/magento-open-source/pages/search/[[...url]].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PageOptions } from '@graphcommerce/framer-next-pages'
import { InContextMaskProvider, cacheFirst, flushMeasurePerf } from '@graphcommerce/graphql'
import { cacheFirst, flushMeasurePerf, PrivateQueryMaskProvider } from '@graphcommerce/graphql'
import type { MenuQueryFragment } from '@graphcommerce/magento-category'
import type {
FilterTypes,
Expand All @@ -8,11 +8,11 @@ import type {
ProductListQuery,
} from '@graphcommerce/magento-product'
import {
ProductFiltersDocument,
ProductListDocument,
extractUrlQuery,
getFilterTypes,
parseParams,
ProductFiltersDocument,
ProductListDocument,
} from '@graphcommerce/magento-product'
import type { CategorySearchQuery } from '@graphcommerce/magento-search'
import {
Expand Down Expand Up @@ -67,7 +67,7 @@ function SearchResultPage(props: SearchResultProps) {
<ProductFiltersProSearchField size='small' formControl={{ sx: { width: '81vw' } }} />
</LayoutHeader>

<InContextMaskProvider mask={productList.mask}>
<PrivateQueryMaskProvider mask={productList.mask}>
{import.meta.graphCommerce.productFiltersPro &&
import.meta.graphCommerce.productFiltersLayout === 'SIDEBAR' && (
<ProductListLayoutSidebar {...productList} menu={menu} />
Expand All @@ -79,7 +79,7 @@ function SearchResultPage(props: SearchResultProps) {
{!import.meta.graphCommerce.productFiltersPro && (
<ProductListLayoutClassic {...productList} menu={menu} />
)}
</InContextMaskProvider>
</PrivateQueryMaskProvider>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ALGOLIA_USER_TOKEN_COOKIE_NAME } from '@graphcommerce/algolia-insights'
import {
type getInContextInput as getInContextInputType,
type useInContextInput as useInContextInputType,
type getPrivateQueryContext as getPrivateQueryContextType,
type usePrivateQueryContext as usePrivateQueryContextType,
} from '@graphcommerce/graphql'
import type { InContextInput } from '@graphcommerce/graphql-mesh'
import type { PrivateContext } from '@graphcommerce/graphql-mesh'
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
import { cookie } from '@graphcommerce/next-ui'

Expand All @@ -12,18 +12,21 @@ export const config: PluginConfig = {
module: '@graphcommerce/graphql',
}

export const getInContextInput: FunctionPlugin<typeof getInContextInputType> = (
export const getPrivateQueryContext: FunctionPlugin<typeof getPrivateQueryContextType> = (
prev,
client,
...args
) => {
const algoliaUserToken = cookie(ALGOLIA_USER_TOKEN_COOKIE_NAME)
const res = prev(client, ...args)
if (!algoliaUserToken) return res
return { ...res, algoliaUserToken } satisfies InContextInput
return { ...res, algoliaUserToken } satisfies PrivateContext
}

export const useInContextInput: FunctionPlugin<typeof useInContextInputType> = (prev, ...args) => {
export const usePrivateQueryContext: FunctionPlugin<typeof usePrivateQueryContextType> = (
prev,
...args
) => {
const algoliaUserToken = cookie(ALGOLIA_USER_TOKEN_COOKIE_NAME)
const res = prev(...args)
if (!algoliaUserToken) return res
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
input InContextInput {
input PrivateContext {
algoliaUserToken: String
}
Loading

0 comments on commit 5dfd3b2

Please sign in to comment.