Skip to content

Commit

Permalink
Merge pull request #2187 from graphcommerce-org/fiv/various
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
paales authored Feb 1, 2024
2 parents 80094c4 + 09a2cc3 commit f711621
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 138 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-pants-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/magento-store': patch
---

redirectOrNotFound would log the incorrect request URL
6 changes: 6 additions & 0 deletions .changeset/spotty-bugs-act.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/twenty-hornets-study.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/two-baboons-wink.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions docs/framework/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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.

Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/hygraph/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions docs/hygraph/property-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ 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)
<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/3226eedb-e58c-4d3f-9516-14ff6ed56f24">
<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/3226eedb-e58c-4d3f-9516-14ff6ed56f24"/>

## Enabling the Application

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.

<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/ec9b55f6-14f6-466e-8a31-0b893ffe1297">
<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/ec9b55f6-14f6-466e-8a31-0b893ffe1297"/>

## Enabling the field

Expand All @@ -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`.

<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/9206f86d-477c-4eaf-bec6-1648874bee5e">
<img width="1792" alt="image" src="https://github.com/graphcommerce-org/graphcommerce/assets/49681263/9206f86d-477c-4eaf-bec6-1648874bee5e"/>

## Start building with your new Dynamic Rows UI!

Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading/graphcommerce-7-to-8.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
3 changes: 0 additions & 3 deletions packages/magento-cart/typePolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 6 additions & 5 deletions packages/magento-customer/components/SignOutForm/signOut.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ApolloClient } from '@graphcommerce/graphql'

export function signOut(client: ApolloClient<object>) {
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()
}
46 changes: 12 additions & 34 deletions packages/magento-customer/typePolicies.ts
Original file line number Diff line number Diff line change
@@ -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<CustomerToken['valid']> = {
read(existing, options) {
if (existing === undefined) return existing

const ref = options.toReference({ __ref: 'CustomerToken' })
const createdAt = options.readField<string>('createdAt', ref)

if (!createdAt) return existing

return new Date().getTime() - new Date(createdAt).getTime() < TOKEN_EXPIRATION_MS
},
}

const generateCustomerToken: FieldPolicy<Mutation['generateCustomerToken']> = {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/magento-store/utils/redirectOrNotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
Expand Down
6 changes: 3 additions & 3 deletions packagesDev/graphql-codegen-markdown-docs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)}`;
},
},
Expand All @@ -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 '';
},
},
Expand Down
6 changes: 3 additions & 3 deletions packagesDev/graphql-codegen-markdown-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
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) => {
Expand All @@ -66,7 +66,7 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
},
InputValueDefinition: {
leave: (node) => {
const defaultValue = node.defaultValue ? ` = ${node.defaultValue}` : ''
const defaultValue = node.defaultValue ? ` = \`${node.defaultValue}\`` : ''
return `${node.name}: ${node.type}${defaultValue}${descriptionText(node)}`
},
},
Expand All @@ -92,7 +92,7 @@ export const plugin: PluginFunction<MarkdownDocsPluginConfig, Types.ComplexPlugi
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 ''
},
},
Expand Down
Loading

0 comments on commit f711621

Please sign in to comment.