@graphcommerce/graphql 9.0.0-canary.99 → 9.0.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -949
- package/{test → __playwright__}/apolloClient.fixture.ts +7 -12
- package/apollo.ts +1 -0
- package/components/GraphQLProvider/GraphQLProvider.tsx +4 -15
- package/components/GraphQLProvider/createCacheReviver.ts +4 -3
- package/components/GraphQLProvider/measurePerformanceLink.ts +66 -36
- package/components/GraphQLProvider/migrateCache.ts +1 -1
- package/components/GraphQLProvider/persistenceMapper.ts +4 -1
- package/components/PrivateQueryMask/PrivateQueryMask.tsx +93 -0
- package/config.ts +10 -3
- package/hooks/{useInContextQuery.ts → usePrivateQuery.ts} +24 -20
- package/hooks/usePrivateQueryContext.ts +20 -0
- package/index.ts +3 -3
- package/link/RemovePrivateContextDirectivesLink.ts +19 -0
- package/package.json +15 -14
- package/schema/InContext.graphqls +3 -3
- package/tsconfig.json +1 -1
- package/utils/cachePolicy.ts +1 -1
- package/utils/getPreviewData.ts +2 -2
- package/components/InContextMask/InContextMask.tsx +0 -92
- package/hooks/useInContextInput.ts +0 -17
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
import { cssFlag, cssNotFlag, useIsSSR } from '@graphcommerce/next-ui'
|
|
3
|
-
import { Box, Skeleton, SkeletonOwnProps, SkeletonProps, SxProps, Theme } from '@mui/material'
|
|
4
|
-
import type { OverrideProps } from '@mui/material/OverridableComponent'
|
|
5
|
-
import React, { createContext, useContext, useMemo } from 'react'
|
|
6
|
-
|
|
7
|
-
type MaskProp = { skeleton?: SkeletonProps }
|
|
8
|
-
|
|
9
|
-
interface InContextMaskTypeMap<
|
|
10
|
-
AdditionalProps = MaskProp,
|
|
11
|
-
RootComponent extends React.ElementType = 'div',
|
|
12
|
-
> {
|
|
13
|
-
props: AdditionalProps & SkeletonOwnProps
|
|
14
|
-
defaultComponent: RootComponent
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type InContextMaskProps<
|
|
18
|
-
RootComponent extends React.ElementType = InContextMaskTypeMap['defaultComponent'],
|
|
19
|
-
AdditionalProps = MaskProp,
|
|
20
|
-
> = OverrideProps<InContextMaskTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
|
|
21
|
-
component?: React.ElementType
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type InContextMaskContextType = { mask: boolean }
|
|
25
|
-
|
|
26
|
-
export const InContextMaskContext = createContext<InContextMaskContextType | undefined>(undefined)
|
|
27
|
-
|
|
28
|
-
export function useInContextInputMask(): InContextMaskContextType {
|
|
29
|
-
const context = useContext(InContextMaskContext)
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
32
|
-
const isSSR = process.env.NODE_ENV === 'development' ? useIsSSR() : false
|
|
33
|
-
|
|
34
|
-
if (!context) {
|
|
35
|
-
if (isSSR)
|
|
36
|
-
console.warn(
|
|
37
|
-
"useInContextInputMask was used without a InContextMaskProvider, this means that customer specific pricing probably isn't working.",
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
return { mask: false }
|
|
41
|
-
}
|
|
42
|
-
return context
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function InContextMaskProvider(props: { mask: boolean; children: React.ReactNode }) {
|
|
46
|
-
const { mask = false, children } = props
|
|
47
|
-
return (
|
|
48
|
-
<InContextMaskContext.Provider value={useMemo(() => ({ mask }), [mask])}>
|
|
49
|
-
{children}
|
|
50
|
-
</InContextMaskContext.Provider>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function useInContextInputMaskSx(props: { sx?: SxProps<Theme>; skeleton?: SkeletonProps }) {
|
|
55
|
-
const { sx = [], skeleton } = props
|
|
56
|
-
const { mask } = useInContextInputMask()
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
mask,
|
|
60
|
-
componentSx: [
|
|
61
|
-
mask && {
|
|
62
|
-
[cssFlag('in-context')]: { display: 'none' },
|
|
63
|
-
},
|
|
64
|
-
...(Array.isArray(sx) ? sx : [sx]),
|
|
65
|
-
],
|
|
66
|
-
maskSx: [
|
|
67
|
-
{
|
|
68
|
-
display: 'inline-block',
|
|
69
|
-
[cssNotFlag('in-context')]: { display: 'none' },
|
|
70
|
-
},
|
|
71
|
-
...(Array.isArray(sx) ? sx : [sx]),
|
|
72
|
-
...(Array.isArray(skeleton?.sx) ? skeleton.sx : [skeleton?.sx]),
|
|
73
|
-
],
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A component that renders a skeleton mask when the user is signed in.
|
|
79
|
-
*/
|
|
80
|
-
export function InContextMask(props: InContextMaskProps) {
|
|
81
|
-
const { skeleton, children, ...rest } = props
|
|
82
|
-
const { mask, componentSx, maskSx } = useInContextInputMaskSx(props)
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<>
|
|
86
|
-
<Box {...rest} sx={componentSx}>
|
|
87
|
-
{children}
|
|
88
|
-
</Box>
|
|
89
|
-
{mask && <Skeleton {...rest} {...skeleton} sx={maskSx} />}
|
|
90
|
-
</>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from '@apollo/client'
|
|
2
|
-
import type { InContextInput } from '@graphcommerce/graphql-mesh'
|
|
3
|
-
|
|
4
|
-
export function getInContextInput(client: ApolloClient<any>): InContextInput | null {
|
|
5
|
-
return null
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Defines a method to handle the current context for the query.
|
|
10
|
-
*
|
|
11
|
-
* Other plugins should be able to define their own scopes and create a plugin on this method to augment the specific scope.
|
|
12
|
-
*
|
|
13
|
-
* @see @graphcommerce/magento-customer/plugins/magentoCustomerGetInContext.ts
|
|
14
|
-
*
|
|
15
|
-
* Note: ONLY return a value if the frontend should use the inContext directive.
|
|
16
|
-
*/
|
|
17
|
-
export const useInContextInput = (): InContextInput | null => null
|