@graphcommerce/magento-store 6.0.2-canary.7 → 6.0.2-canary.9

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 6.0.2-canary.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1875](https://github.com/graphcommerce-org/graphcommerce/pull/1875) [`4325f6556`](https://github.com/graphcommerce-org/graphcommerce/commit/4325f6556308fe96e262e03935f37dc252f72c2e) - When trying to redirect it would do another call to fetch the config while that was already done previously ([@paales](https://github.com/paales))
8
+
9
+ ## 6.0.2-canary.8
10
+
3
11
  ## 6.0.2-canary.7
4
12
 
5
13
  ## 6.0.2-canary.6
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-store",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "6.0.2-canary.7",
5
+ "version": "6.0.2-canary.9",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,15 +12,15 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "6.0.2-canary.7",
16
- "@graphcommerce/prettier-config-pwa": "6.0.2-canary.7",
17
- "@graphcommerce/typescript-config-pwa": "6.0.2-canary.7"
15
+ "@graphcommerce/eslint-config-pwa": "6.0.2-canary.9",
16
+ "@graphcommerce/prettier-config-pwa": "6.0.2-canary.9",
17
+ "@graphcommerce/typescript-config-pwa": "6.0.2-canary.9"
18
18
  },
19
19
  "dependencies": {
20
- "@graphcommerce/graphql": "6.0.2-canary.7",
21
- "@graphcommerce/graphql-mesh": "6.0.2-canary.7",
22
- "@graphcommerce/image": "6.0.2-canary.7",
23
- "@graphcommerce/next-ui": "6.0.2-canary.7"
20
+ "@graphcommerce/graphql": "6.0.2-canary.9",
21
+ "@graphcommerce/graphql-mesh": "6.0.2-canary.9",
22
+ "@graphcommerce/image": "6.0.2-canary.9",
23
+ "@graphcommerce/next-ui": "6.0.2-canary.9"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@lingui/react": "^3.13.2",
@@ -1,8 +1,13 @@
1
1
  import { ParsedUrlQuery } from 'querystring'
2
- import { ApolloClient, flushMeasurePerf, NormalizedCacheObject } from '@graphcommerce/graphql'
2
+ import {
3
+ ApolloClient,
4
+ ApolloQueryResult,
5
+ flushMeasurePerf,
6
+ NormalizedCacheObject,
7
+ } from '@graphcommerce/graphql'
3
8
  import { nonNullable, isTypename } from '@graphcommerce/next-ui'
4
9
  import { Redirect } from 'next'
5
- import { StoreConfigDocument } from '../StoreConfig.gql'
10
+ import { StoreConfigQuery } from '../StoreConfig.gql'
6
11
  import { defaultLocale } from '../localeToStore'
7
12
  import { HandleRedirectDocument } from './HandleRedirect.gql'
8
13
 
@@ -39,6 +44,7 @@ const redirect = (from: string, to: string, permanent: boolean, locale?: string)
39
44
 
40
45
  export async function redirectOrNotFound(
41
46
  client: ApolloClient<NormalizedCacheObject>,
47
+ config: Promise<ApolloQueryResult<StoreConfigQuery>> | ApolloQueryResult<StoreConfigQuery>,
42
48
  params?: ParsedUrlQuery,
43
49
  locale?: string,
44
50
  ): RedirectOr404Return {
@@ -49,14 +55,13 @@ export async function redirectOrNotFound(
49
55
 
50
56
  try {
51
57
  // Get the configured suffixes from the store config
52
- const { product_url_suffix: prodSuffix, category_url_suffix: catSuffix } =
53
- (await client.query({ query: StoreConfigDocument })).data.storeConfig ?? {}
58
+ const { product_url_suffix, category_url_suffix } = (await config).data.storeConfig ?? {}
54
59
 
55
60
  const candidates = new Set([from])
56
61
 
57
62
  // If the incomming URL contains a suffix, we check if the URL without the suffix exists
58
63
  // if the incomming URL does not contain a suffix, we check if the URL with the suffix exists
59
- const suffixes = [prodSuffix, catSuffix].filter(nonNullable)
64
+ const suffixes = [product_url_suffix, category_url_suffix].filter(nonNullable)
60
65
  suffixes.forEach((suffix) => {
61
66
  candidates.add(from.endsWith(suffix) ? from.slice(0, -suffix.length) : `${from}${suffix}`)
62
67
  })