From 6c4cee8469ee4934281bda53ac96aeb5af2f9479 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Thu, 1 Feb 2024 11:16:22 +0100 Subject: [PATCH 1/4] Make sure the config page can be properly rendered in the docs --- .changeset/spotty-bugs-act.md | 6 + docs/framework/config.md | 16 +- docs/hygraph/cli.md | 4 +- docs/hygraph/property-picker.md | 10 +- docs/upgrading/graphcommerce-7-to-8.md | 2 +- .../dist/index.js | 6 +- .../src/index.ts | 6 +- .../next-config/dist/generated/config.js | 187 +++++++++++------- 8 files changed, 142 insertions(+), 95 deletions(-) create mode 100644 .changeset/spotty-bugs-act.md diff --git a/.changeset/spotty-bugs-act.md b/.changeset/spotty-bugs-act.md new file mode 100644 index 0000000000..6127e9d711 --- /dev/null +++ b/.changeset/spotty-bugs-act.md @@ -0,0 +1,6 @@ +--- +"@graphcommerce/graphql-codegen-markdown-docs": patch +"@graphcommerce/docs": patch +--- + +Make sure the config page can be properly rendered in the docs diff --git a/docs/framework/config.md b/docs/framework/config.md index 30a8cb36c0..d3568fffc1 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -115,12 +115,12 @@ When Magento's StoreConfig adds this value, this can be replaced. Use compare functionality -#### compareVariant: 'CHECKBOX' | 'ICON' = 'ICON' +#### compareVariant: CHECKBOX | ICON = `ICON` By default the compare feature is denoted with a 'compare ICON' (2 arrows facing one another). This may be fine for experienced users, but for more clarity it's also possible to present the compare feature as a CHECKBOX accompanied by the 'Compare' label -#### configurableVariantForSimple: boolean = false +#### configurableVariantForSimple: boolean = `false` If a simple product is part of a Configurable product page, should the simple product be rendered as a configured option of the configurable product page? @@ -133,19 +133,19 @@ Magento also returns the Simple product and the Configurable product the simple If that is the case we render the configurable product page instead of the simple product page but the options to select the simple product are pre-selected. -#### configurableVariantValues: [MagentoConfigurableVariantValues](#MagentoConfigurableVariantValues) = { content: true, url: true } +#### configurableVariantValues: [MagentoConfigurableVariantValues](#MagentoConfigurableVariantValues) = `{ content: true, url: true }` When a user selects a variant, it will switch the values on the configurable page with the values of the configured variant. Enabling options here will allow switching of those variants. -#### crossSellsHideCartItems: boolean = false +#### crossSellsHideCartItems: boolean = `false` Determines if cross sell items should be shown when the user already has the product in their cart. This will result in a product will popping off the screen when you add it to the cart. Default: 'false' -#### crossSellsRedirectItems: boolean = false +#### crossSellsRedirectItems: boolean = `false` Determines if, after adding a cross-sell item to the cart, the user should be redirected to the cross-sell items of the product they just added. @@ -163,7 +163,7 @@ This value should match Magento 2's configuration value for Debug configuration for GraphCommerce -#### demoMode: boolean = true +#### demoMode: boolean = `true` Enables some demo specific code that is probably not useful for a project: @@ -263,7 +263,7 @@ By default GraphCommerce will statically generate all product and category pages To enable next.js' preview mode, configure the secret you'd like to use. -#### productFiltersLayout: 'DEFAULT' | 'SIDEBAR' = 'DEFAULT' +#### productFiltersLayout: DEFAULT | SIDEBAR = `DEFAULT` Layout how the filters are rendered. DEFAULT: Will be rendered as horzontal chips on desktop and mobile @@ -427,6 +427,6 @@ Number of recently viewed products to be stored in localStorage SidebarGalleryConfig will contain all configuration values for the Sidebar Gallery component. -#### paginationVariant: 'DOTS' | 'THUMBNAILS_BOTTOM' +#### paginationVariant: DOTS | THUMBNAILS_BOTTOM Variant used for the pagination \ No newline at end of file diff --git a/docs/hygraph/cli.md b/docs/hygraph/cli.md index bc8b0177aa..e8a03724c2 100644 --- a/docs/hygraph/cli.md +++ b/docs/hygraph/cli.md @@ -58,9 +58,9 @@ The following steps are needed to utilize this tool: 1. Copy the project ID from the URL when logged in `https://app.hygraph.com/PROJECT_ID_IS_HERE/master` 2. Add the project ID to your env file: - `GC_HYGRAPH_PROJECT_ID=”{YOUR_PROJECT_ID}”` + `GC_HYGRAPH_PROJECT_ID="{YOUR_PROJECT_ID}"` 4. Add your hygraphManagementApi to your env file like this: - `GC_HYGRAPH_MANAGEMENT_API="{YOUR_MANAGEMENT_API}"` + 1. Copy the Management API URL and add to your env file: `GC_HYGRAPH_MANAGEMENT_API="{YOUR_MANAGEMENT_API}"` 5. Run `yarn graphcommerce hygraph-migrate` 6. Select the migration you want to run and press enter. 7. The migrations should now be applied, check your Hygraph Schema if changes diff --git a/docs/hygraph/property-picker.md b/docs/hygraph/property-picker.md index bfcd601b3d..e65effb58c 100644 --- a/docs/hygraph/property-picker.md +++ b/docs/hygraph/property-picker.md @@ -6,11 +6,9 @@ row to each page. These rules hinge on shared attributes among the pages, with a category being a typical example of such an attribute. To enable the Dynamic Row UI Extension, follow the installation instructions as below. -> Installation -> -> [Click here to install the Dynamic Row UI Extension](https://app.hygraph.com/apps/dynamic-row-property-picker/new) +> Installation: [Click here to install the Dynamic Row UI Extension](https://app.hygraph.com/apps/dynamic-row-property-picker/new) -image +image ## Enabling the Application @@ -18,7 +16,7 @@ Once you click the link and authorize the application, you'll be taken to the app's configuration page. On this page, you can switch the application on or off as needed. -image +image ## Enabling the field @@ -37,7 +35,7 @@ Replace the existing fields with the new `Property picker` field in the right si (it should be under `Slug` and above `Rich text`). While adding the `Property picker` field make sure that you make it `required`. -image +image ## Start building with your new Dynamic Rows UI! diff --git a/docs/upgrading/graphcommerce-7-to-8.md b/docs/upgrading/graphcommerce-7-to-8.md index 6ad9ce53e5..804e5789b8 100644 --- a/docs/upgrading/graphcommerce-7-to-8.md +++ b/docs/upgrading/graphcommerce-7-to-8.md @@ -1,4 +1,4 @@ -# Upgrading from GraphCommerce 6 to 7 +# Upgrading from GraphCommerce 7 to 8 Depending on the amounts of customisations you've made, there are some manual steps. Please follow the regular [upgrade steps first](./readme.md). diff --git a/packagesDev/graphql-codegen-markdown-docs/dist/index.js b/packagesDev/graphql-codegen-markdown-docs/dist/index.js index c5e3a36fb4..072238c978 100644 --- a/packagesDev/graphql-codegen-markdown-docs/dist/index.js +++ b/packagesDev/graphql-codegen-markdown-docs/dist/index.js @@ -38,7 +38,7 @@ config) => { BooleanValue: { leave: (node) => (node.value ? 'true' : 'false'), }, - EnumValue: { leave: (node) => `'${node.value}'` }, + EnumValue: { leave: (node) => `${node.value}` }, IntValue: { leave: (node) => node.value }, ObjectValue: { leave: (node) => { @@ -56,7 +56,7 @@ config) => { }, InputValueDefinition: { leave: (node) => { - const defaultValue = node.defaultValue ? ` = ${node.defaultValue}` : ''; + const defaultValue = node.defaultValue ? ` = \`${node.defaultValue}\`` : ''; return `${node.name}: ${node.type}${defaultValue}${descriptionText(node)}`; }, }, @@ -80,7 +80,7 @@ config) => { EnumTypeDefinition: { leave: (node) => { if (node.values) - enumStings.set(node.name, node.values.map((v) => `'${v.trim()}'`).join(' | ')); + enumStings.set(node.name, node.values.map((v) => `${v.trim()}`).join(' | ')); return ''; }, }, diff --git a/packagesDev/graphql-codegen-markdown-docs/src/index.ts b/packagesDev/graphql-codegen-markdown-docs/src/index.ts index c72606dc03..0bf57bb1c8 100644 --- a/packagesDev/graphql-codegen-markdown-docs/src/index.ts +++ b/packagesDev/graphql-codegen-markdown-docs/src/index.ts @@ -48,7 +48,7 @@ export const plugin: PluginFunction (node.value ? 'true' : 'false'), }, - EnumValue: { leave: (node) => `'${node.value}'` }, + EnumValue: { leave: (node) => `${node.value}` }, IntValue: { leave: (node) => node.value }, ObjectValue: { leave: (node) => { @@ -66,7 +66,7 @@ export const plugin: PluginFunction { - const defaultValue = node.defaultValue ? ` = ${node.defaultValue}` : '' + const defaultValue = node.defaultValue ? ` = \`${node.defaultValue}\`` : '' return `${node.name}: ${node.type}${defaultValue}${descriptionText(node)}` }, }, @@ -92,7 +92,7 @@ export const plugin: PluginFunction { if (node.values) - enumStings.set(node.name, node.values.map((v) => `'${v.trim()}'`).join(' | ')) + enumStings.set(node.name, node.values.map((v) => `${v.trim()}`).join(' | ')) return '' }, }, diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index d754648ddf..d125aaeb5c 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -1,94 +1,137 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0; -/* eslint-disable */ -const zod_1 = require("zod"); -const isDefinedNonNullAny = (v) => v !== undefined && v !== null; -exports.isDefinedNonNullAny = isDefinedNonNullAny; -exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v)); -exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']); -exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']); -exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']); +/* eslint-disable */ "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + CompareVariantSchema: function() { + return CompareVariantSchema; + }, + GraphCommerceConfigSchema: function() { + return GraphCommerceConfigSchema; + }, + GraphCommerceDebugConfigSchema: function() { + return GraphCommerceDebugConfigSchema; + }, + GraphCommerceStorefrontConfigSchema: function() { + return GraphCommerceStorefrontConfigSchema; + }, + MagentoConfigurableVariantValuesSchema: function() { + return MagentoConfigurableVariantValuesSchema; + }, + ProductFiltersLayoutSchema: function() { + return ProductFiltersLayoutSchema; + }, + RecentlyViewedProductsConfigSchema: function() { + return RecentlyViewedProductsConfigSchema; + }, + SidebarGalleryConfigSchema: function() { + return SidebarGalleryConfigSchema; + }, + SidebarGalleryPaginationVariantSchema: function() { + return SidebarGalleryPaginationVariantSchema; + }, + definedNonNullAnySchema: function() { + return definedNonNullAnySchema; + }, + isDefinedNonNullAny: function() { + return isDefinedNonNullAny; + } +}); +const _zod = require("zod"); +const isDefinedNonNullAny = (v)=>v !== undefined && v !== null; +const definedNonNullAnySchema = _zod.z.any().refine((v)=>isDefinedNonNullAny(v)); +const CompareVariantSchema = _zod.z.enum([ + "CHECKBOX", + "ICON" +]); +const ProductFiltersLayoutSchema = _zod.z.enum([ + "DEFAULT", + "SIDEBAR" +]); +const SidebarGalleryPaginationVariantSchema = _zod.z.enum([ + "DOTS", + "THUMBNAILS_BOTTOM" +]); function GraphCommerceConfigSchema() { - return zod_1.z.object({ - canonicalBaseUrl: zod_1.z.string().min(1), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - compare: zod_1.z.boolean().nullish(), - compareVariant: exports.CompareVariantSchema.nullish(), - configurableVariantForSimple: zod_1.z.boolean().nullish(), + return _zod.z.object({ + canonicalBaseUrl: _zod.z.string().min(1), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + compare: _zod.z.boolean().nullish(), + compareVariant: CompareVariantSchema.nullish(), + configurableVariantForSimple: _zod.z.boolean().nullish(), configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(), - crossSellsHideCartItems: zod_1.z.boolean().nullish(), - crossSellsRedirectItems: zod_1.z.boolean().nullish(), - customerRequireEmailConfirmation: zod_1.z.boolean().nullish(), + crossSellsHideCartItems: _zod.z.boolean().nullish(), + crossSellsRedirectItems: _zod.z.boolean().nullish(), + customerRequireEmailConfirmation: _zod.z.boolean().nullish(), debug: GraphCommerceDebugConfigSchema().nullish(), - demoMode: zod_1.z.boolean().nullish(), - enableGuestCheckoutLogin: zod_1.z.boolean().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - hygraphEndpoint: zod_1.z.string().min(1), - hygraphManagementApi: zod_1.z.string().nullish(), - hygraphProjectId: zod_1.z.string().nullish(), - hygraphWriteAccessEndpoint: zod_1.z.string().nullish(), - hygraphWriteAccessToken: zod_1.z.string().nullish(), - limitSsg: zod_1.z.boolean().nullish(), - magentoEndpoint: zod_1.z.string().min(1), - previewSecret: zod_1.z.string().nullish(), - productFiltersLayout: exports.ProductFiltersLayoutSchema.nullish(), - productFiltersPro: zod_1.z.boolean().nullish(), - productRoute: zod_1.z.string().nullish(), + demoMode: _zod.z.boolean().nullish(), + enableGuestCheckoutLogin: _zod.z.boolean().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + hygraphEndpoint: _zod.z.string().min(1), + hygraphManagementApi: _zod.z.string().nullish(), + hygraphProjectId: _zod.z.string().nullish(), + hygraphWriteAccessEndpoint: _zod.z.string().nullish(), + hygraphWriteAccessToken: _zod.z.string().nullish(), + limitSsg: _zod.z.boolean().nullish(), + magentoEndpoint: _zod.z.string().min(1), + previewSecret: _zod.z.string().nullish(), + productFiltersLayout: ProductFiltersLayoutSchema.nullish(), + productFiltersPro: _zod.z.boolean().nullish(), + productRoute: _zod.z.string().nullish(), recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(), - robotsAllow: zod_1.z.boolean().nullish(), + robotsAllow: _zod.z.boolean().nullish(), sidebarGallery: SidebarGalleryConfigSchema().nullish(), - storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()), - wishlistHideForGuests: zod_1.z.boolean().nullish(), - wishlistShowFeedbackMessage: zod_1.z.boolean().nullish() + storefront: _zod.z.array(GraphCommerceStorefrontConfigSchema()), + wishlistHideForGuests: _zod.z.boolean().nullish(), + wishlistShowFeedbackMessage: _zod.z.boolean().nullish() }); } -exports.GraphCommerceConfigSchema = GraphCommerceConfigSchema; function GraphCommerceDebugConfigSchema() { - return zod_1.z.object({ - pluginStatus: zod_1.z.boolean().nullish(), - sessions: zod_1.z.boolean().nullish(), - webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(), - webpackDuplicatesPlugin: zod_1.z.boolean().nullish() + return _zod.z.object({ + pluginStatus: _zod.z.boolean().nullish(), + sessions: _zod.z.boolean().nullish(), + webpackCircularDependencyPlugin: _zod.z.boolean().nullish(), + webpackDuplicatesPlugin: _zod.z.boolean().nullish() }); } -exports.GraphCommerceDebugConfigSchema = GraphCommerceDebugConfigSchema; function GraphCommerceStorefrontConfigSchema() { - return zod_1.z.object({ - canonicalBaseUrl: zod_1.z.string().nullish(), - cartDisplayPricesInclTax: zod_1.z.boolean().nullish(), - defaultLocale: zod_1.z.boolean().nullish(), - domain: zod_1.z.string().nullish(), - googleAnalyticsId: zod_1.z.string().nullish(), - googleRecaptchaKey: zod_1.z.string().nullish(), - googleTagmanagerId: zod_1.z.string().nullish(), - hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(), - linguiLocale: zod_1.z.string().nullish(), - locale: zod_1.z.string().min(1), - magentoStoreCode: zod_1.z.string().min(1) + return _zod.z.object({ + canonicalBaseUrl: _zod.z.string().nullish(), + cartDisplayPricesInclTax: _zod.z.boolean().nullish(), + defaultLocale: _zod.z.boolean().nullish(), + domain: _zod.z.string().nullish(), + googleAnalyticsId: _zod.z.string().nullish(), + googleRecaptchaKey: _zod.z.string().nullish(), + googleTagmanagerId: _zod.z.string().nullish(), + hygraphLocales: _zod.z.array(_zod.z.string().min(1)).nullish(), + linguiLocale: _zod.z.string().nullish(), + locale: _zod.z.string().min(1), + magentoStoreCode: _zod.z.string().min(1) }); } -exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema; function MagentoConfigurableVariantValuesSchema() { - return zod_1.z.object({ - content: zod_1.z.boolean().nullish(), - gallery: zod_1.z.boolean().nullish(), - url: zod_1.z.boolean().nullish() + return _zod.z.object({ + content: _zod.z.boolean().nullish(), + gallery: _zod.z.boolean().nullish(), + url: _zod.z.boolean().nullish() }); } -exports.MagentoConfigurableVariantValuesSchema = MagentoConfigurableVariantValuesSchema; function RecentlyViewedProductsConfigSchema() { - return zod_1.z.object({ - enabled: zod_1.z.boolean().nullish(), - maxCount: zod_1.z.number().nullish() + return _zod.z.object({ + enabled: _zod.z.boolean().nullish(), + maxCount: _zod.z.number().nullish() }); } -exports.RecentlyViewedProductsConfigSchema = RecentlyViewedProductsConfigSchema; function SidebarGalleryConfigSchema() { - return zod_1.z.object({ - paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish() + return _zod.z.object({ + paginationVariant: SidebarGalleryPaginationVariantSchema.nullish() }); } -exports.SidebarGalleryConfigSchema = SidebarGalleryConfigSchema; From 61f90afc8bc229b2cd4793f724509783af138deb Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Thu, 1 Feb 2024 11:39:54 +0100 Subject: [PATCH 2/4] redirectOrNotFound would log the incorrect request URL --- .changeset/popular-pants-learn.md | 5 +++++ packages/magento-store/utils/redirectOrNotFound.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/popular-pants-learn.md diff --git a/.changeset/popular-pants-learn.md b/.changeset/popular-pants-learn.md new file mode 100644 index 0000000000..989640d13e --- /dev/null +++ b/.changeset/popular-pants-learn.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/magento-store': patch +--- + +redirectOrNotFound would log the incorrect request URL diff --git a/packages/magento-store/utils/redirectOrNotFound.ts b/packages/magento-store/utils/redirectOrNotFound.ts index 43e7f991f0..a77c87eea4 100644 --- a/packages/magento-store/utils/redirectOrNotFound.ts +++ b/packages/magento-store/utils/redirectOrNotFound.ts @@ -32,7 +32,7 @@ const redirect = (from: string, to: string, permanent: boolean, locale?: string) // eslint-disable-next-line no-console console.log( - `[redirectOrNotFound: /${prefix}/${from}] ${ + `[redirectOrNotFound: ${prefix ? `/${prefix}` : ''}/${from}] ${ permanent ? 'Permanent' : 'Temporary' } redirect to ${destination}`, ) From ee969bfc5415392747b04e0484685f5c611a2559 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Thu, 1 Feb 2024 12:24:21 +0100 Subject: [PATCH 3/4] After signing out the currentCartId was still returning a value causing the cart to be shown after signing out --- .changeset/two-baboons-wink.md | 5 +++++ packages/magento-cart/typePolicies.ts | 3 --- .../components/SignOutForm/signOut.ts | 11 ++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .changeset/two-baboons-wink.md diff --git a/.changeset/two-baboons-wink.md b/.changeset/two-baboons-wink.md new file mode 100644 index 0000000000..545c0fdead --- /dev/null +++ b/.changeset/two-baboons-wink.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-customer": patch +--- + +After signing out the currentCartId was still returning a value causing the cart to be shown after signing out diff --git a/packages/magento-cart/typePolicies.ts b/packages/magento-cart/typePolicies.ts index 67e108f9fd..5b37f34066 100644 --- a/packages/magento-cart/typePolicies.ts +++ b/packages/magento-cart/typePolicies.ts @@ -27,15 +27,12 @@ export const cartTypePolicies: StrictTypedTypePolicies = { }, }, }, - Query: { fields: { - currentCartId: (_, { toReference }) => toReference({ __typename: 'CurrentCartId' }), cart: (_, { args, toReference }) => toReference({ __typename: 'Cart', id: (args as QuerycartArgs)?.cart_id }), }, }, - Mutation: { fields: { createEmptyCart: { diff --git a/packages/magento-customer/components/SignOutForm/signOut.ts b/packages/magento-customer/components/SignOutForm/signOut.ts index 8815fb2f8e..8557aaac17 100644 --- a/packages/magento-customer/components/SignOutForm/signOut.ts +++ b/packages/magento-customer/components/SignOutForm/signOut.ts @@ -1,9 +1,10 @@ import { ApolloClient } from '@graphcommerce/graphql' export function signOut(client: ApolloClient) { - client.cache.evict({ fieldName: 'currentCartId', broadcast: true }) - client.cache.evict({ fieldName: 'cart', broadcast: true }) - client.cache.evict({ fieldName: 'customerToken', broadcast: true }) - client.cache.evict({ fieldName: 'customer', broadcast: true }) - client.cache.evict({ fieldName: 'customerCart', broadcast: true }) + client.cache.evict({ fieldName: 'currentCartId' }) + client.cache.evict({ fieldName: 'cart' }) + client.cache.evict({ fieldName: 'customerToken' }) + client.cache.evict({ fieldName: 'customer' }) + client.cache.evict({ fieldName: 'customerCart' }) + client.cache.gc() } From 09a2cc35ceb5e714ffd02e573eebe7de842ae327 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Thu, 1 Feb 2024 12:25:52 +0100 Subject: [PATCH 4/4] Do not try to automatically invalidate the current token and fully rely on the Session Expired dialog --- .changeset/twenty-hornets-study.md | 5 +++ packages/magento-customer/typePolicies.ts | 46 ++++++----------------- 2 files changed, 17 insertions(+), 34 deletions(-) create mode 100644 .changeset/twenty-hornets-study.md diff --git a/.changeset/twenty-hornets-study.md b/.changeset/twenty-hornets-study.md new file mode 100644 index 0000000000..baa9195d01 --- /dev/null +++ b/.changeset/twenty-hornets-study.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-customer": patch +--- + +Do not try to automatically invalidate the current token and fully rely on the Session Expired dialog diff --git a/packages/magento-customer/typePolicies.ts b/packages/magento-customer/typePolicies.ts index 3c0fff0ff1..6c53cc9b6f 100644 --- a/packages/magento-customer/typePolicies.ts +++ b/packages/magento-customer/typePolicies.ts @@ -1,53 +1,31 @@ import type { FieldPolicy, MigrateCache, StrictTypedTypePolicies } from '@graphcommerce/graphql' -import type { CustomerToken, Mutation } from '@graphcommerce/graphql-mesh' +import type { Mutation } from '@graphcommerce/graphql-mesh' import { CustomerTokenDocument } from './hooks/CustomerToken.gql' -import { IsEmailAvailableDocument } from './hooks/IsEmailAvailable.gql' - -const TOKEN_EXPIRATION_MS = 60 * 60 * 1000 - -const valid: FieldPolicy = { - read(existing, options) { - if (existing === undefined) return existing - - const ref = options.toReference({ __ref: 'CustomerToken' }) - const createdAt = options.readField('createdAt', ref) - - if (!createdAt) return existing - - return new Date().getTime() - new Date(createdAt).getTime() < TOKEN_EXPIRATION_MS - }, -} const generateCustomerToken: FieldPolicy = { keyArgs: () => '', merge(_existing, incoming, options) { if (!options.isReference(incoming)) return incoming - const write = () => { - options.cache.writeQuery({ - query: CustomerTokenDocument, - broadcast: true, - data: { - customerToken: { - __typename: 'CustomerToken', - token: options.readField('token', incoming) as string, - createdAt: new Date().toUTCString(), - valid: true, - }, + options.cache.writeQuery({ + query: CustomerTokenDocument, + broadcast: true, + data: { + customerToken: { + __typename: 'CustomerToken', + token: options.readField('token', incoming) as string, + createdAt: new Date().toUTCString(), + valid: true, }, - }) - } - write() + }, + }) - // Broadcasts the query after the token expiration so UI gets updated - setTimeout(write, TOKEN_EXPIRATION_MS) return incoming }, } export const customerTypePolicies: StrictTypedTypePolicies = { Mutation: { fields: { generateCustomerToken } }, - CustomerToken: { fields: { valid } }, } export const migrateCustomer: MigrateCache = (oldCache, newCache) => {