@graphcommerce/hygraph-ui 10.0.0-canary.68 → 10.0.0-canary.72
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,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 10.0.0-canary.72
|
|
4
|
+
|
|
5
|
+
## 10.0.0-canary.71
|
|
6
|
+
|
|
7
|
+
## 10.0.0-canary.70
|
|
8
|
+
|
|
9
|
+
### Major Changes
|
|
10
|
+
|
|
11
|
+
- [#2565](https://github.com/graphcommerce-org/graphcommerce/pull/2565) [`c96dfcd`](https://github.com/graphcommerce-org/graphcommerce/commit/c96dfcdca981baca387c270ad9e2b9515cdd00cc) - Updated to Apollo Client 4 ([@paales](https://github.com/paales))
|
|
12
|
+
|
|
13
|
+
## 10.0.0-canary.69
|
|
14
|
+
|
|
3
15
|
## 10.0.0-canary.68
|
|
4
16
|
|
|
5
17
|
## 10.0.0-canary.67
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { cacheFirst } from '@graphcommerce/graphql'
|
|
2
|
-
import type { ApolloClient
|
|
2
|
+
import type { ApolloClient } from '@apollo/client'
|
|
3
3
|
import type { HygraphAllPagesQuery } from '../graphql'
|
|
4
4
|
import { HygraphAllPagesDocument } from '../graphql'
|
|
5
5
|
|
|
6
6
|
type Urls = { url: string }
|
|
7
7
|
|
|
8
8
|
export async function getAllHygraphPages(
|
|
9
|
-
client: ApolloClient
|
|
9
|
+
client: ApolloClient,
|
|
10
10
|
options: { pageSize?: number } = {},
|
|
11
11
|
) {
|
|
12
12
|
const { pageSize = 100 } = options
|
|
@@ -16,10 +16,11 @@ export async function getAllHygraphPages(
|
|
|
16
16
|
variables: { first: pageSize },
|
|
17
17
|
fetchPolicy: cacheFirst(client),
|
|
18
18
|
})
|
|
19
|
-
const pages: Promise<ApolloQueryResult<HygraphAllPagesQuery>>[] = [query]
|
|
20
19
|
|
|
21
20
|
const { data } = await query
|
|
22
|
-
const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize)
|
|
21
|
+
const totalPages = data ? Math.ceil(data.pagesConnection.aggregate.count / pageSize) : 1
|
|
22
|
+
|
|
23
|
+
const pages = [query]
|
|
23
24
|
|
|
24
25
|
if (totalPages > 1) {
|
|
25
26
|
for (let i = 2; i <= totalPages; i++) {
|
|
@@ -34,8 +35,9 @@ export async function getAllHygraphPages(
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const paths: Urls[] = (await Promise.all(pages))
|
|
37
|
-
.map((q) => q.data
|
|
38
|
+
.map((q) => q.data?.pages ?? [])
|
|
38
39
|
.flat(1)
|
|
40
|
+
.filter((page): page is NonNullable<typeof page> & { url: string } => !!page?.url)
|
|
39
41
|
.map((page) => ({
|
|
40
42
|
url: page.url,
|
|
41
43
|
}))
|
package/lib/getHygraphPaths.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { PageWhereInput } from '@graphcommerce/graphql-mesh'
|
|
2
|
-
import type { ApolloClient
|
|
2
|
+
import type { ApolloClient } from '@apollo/client'
|
|
3
3
|
import type { GetStaticPathsResult } from 'next'
|
|
4
|
-
import type { HygraphStaticPathsQuery } from '../graphql/HygraphStaticPaths.gql'
|
|
5
4
|
import { HygraphStaticPathsDocument } from '../graphql/HygraphStaticPaths.gql'
|
|
6
5
|
|
|
7
6
|
type Return = GetStaticPathsResult<{ url: string }>
|
|
8
7
|
|
|
9
8
|
export async function getHygraphStaticPaths(
|
|
10
|
-
client: ApolloClient
|
|
9
|
+
client: ApolloClient,
|
|
11
10
|
locale: string,
|
|
12
11
|
options: { pageSize?: number; filter?: PageWhereInput } = {},
|
|
13
12
|
) {
|
|
@@ -16,10 +15,11 @@ export async function getHygraphStaticPaths(
|
|
|
16
15
|
query: HygraphStaticPathsDocument,
|
|
17
16
|
variables: { pageSize, where: filter },
|
|
18
17
|
})
|
|
19
|
-
const pages: Promise<ApolloQueryResult<HygraphStaticPathsQuery>>[] = [query]
|
|
20
18
|
|
|
21
19
|
const { data } = await query
|
|
22
|
-
const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize)
|
|
20
|
+
const totalPages = data ? Math.ceil(data.pagesConnection.aggregate.count / pageSize) : 1
|
|
21
|
+
|
|
22
|
+
const pages = [query]
|
|
23
23
|
|
|
24
24
|
if (totalPages > 1) {
|
|
25
25
|
for (let i = 2; i <= totalPages; i++) {
|
|
@@ -33,9 +33,10 @@ export async function getHygraphStaticPaths(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const paths: Return['paths'] = (await Promise.all(pages))
|
|
36
|
-
.map((q) => q.data
|
|
36
|
+
.map((q) => q.data?.pages ?? [])
|
|
37
37
|
.flat(1)
|
|
38
|
-
.
|
|
38
|
+
.filter((page): page is NonNullable<typeof page> & { url: string } => !!page?.url)
|
|
39
|
+
.map((page) => ({ params: { url: page.url }, locale }))
|
|
39
40
|
|
|
40
41
|
return paths
|
|
41
42
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApolloClient
|
|
1
|
+
import type { ApolloClient } from '@graphcommerce/graphql'
|
|
2
2
|
import type { HygraphPagesQuery } from '../graphql'
|
|
3
3
|
import { HygraphPagesDocument } from '../graphql'
|
|
4
4
|
import { getAllHygraphPages } from './getAllHygraphPages'
|
|
@@ -10,7 +10,7 @@ import { getAllHygraphPages } from './getAllHygraphPages'
|
|
|
10
10
|
* - Implements an alias sytem to merge the content of multiple pages.
|
|
11
11
|
*/
|
|
12
12
|
async function pageContent(
|
|
13
|
-
client: ApolloClient
|
|
13
|
+
client: ApolloClient,
|
|
14
14
|
url: string,
|
|
15
15
|
cached: boolean,
|
|
16
16
|
): Promise<{ data: HygraphPagesQuery }> {
|
|
@@ -34,13 +34,20 @@ async function pageContent(
|
|
|
34
34
|
// Only do the query when there the page is found in the allRoutes
|
|
35
35
|
const found = allRoutes.some((page) => page.url === url)
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (found) {
|
|
38
|
+
const result = await client.query({
|
|
39
|
+
query: HygraphPagesDocument,
|
|
40
|
+
variables: { url },
|
|
41
|
+
fetchPolicy,
|
|
42
|
+
})
|
|
43
|
+
return { data: result.data ?? { pages: [] } }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { data: { pages: [] } }
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export async function hygraphPageContent(
|
|
43
|
-
client: ApolloClient
|
|
50
|
+
client: ApolloClient,
|
|
44
51
|
url: string,
|
|
45
52
|
additionalProperties?: Promise<object> | object,
|
|
46
53
|
cached = false,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.0.0-canary.
|
|
5
|
+
"version": "10.0.0-canary.72",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^10.0.0-canary.
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.
|
|
17
|
-
"@graphcommerce/graphql": "^10.0.0-canary.
|
|
18
|
-
"@graphcommerce/image": "^10.0.0-canary.
|
|
19
|
-
"@graphcommerce/next-ui": "^10.0.0-canary.
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^10.0.0-canary.72",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.72",
|
|
17
|
+
"@graphcommerce/graphql": "^10.0.0-canary.72",
|
|
18
|
+
"@graphcommerce/image": "^10.0.0-canary.72",
|
|
19
|
+
"@graphcommerce/next-ui": "^10.0.0-canary.72",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.72",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.72",
|
|
22
22
|
"@mui/material": "^7.0.0",
|
|
23
23
|
"next": "*",
|
|
24
24
|
"react": "^19.2.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql'
|
|
2
|
-
import {
|
|
2
|
+
import { SetContextLink } from '@graphcommerce/graphql'
|
|
3
3
|
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
4
4
|
|
|
5
5
|
export const config: PluginConfig = {
|
|
@@ -18,16 +18,16 @@ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, co
|
|
|
18
18
|
|
|
19
19
|
const locales = conf.storefront.hygraphLocales
|
|
20
20
|
|
|
21
|
-
const hygraphLink =
|
|
22
|
-
|
|
23
|
-
if (locales)
|
|
21
|
+
const hygraphLink = new SetContextLink((prevContext) => {
|
|
22
|
+
const headers: Record<string, string> = { ...prevContext.headers }
|
|
23
|
+
if (locales) headers['gcms-locales'] = locales.join(',')
|
|
24
24
|
|
|
25
25
|
const stage = conf.previewData?.hygraphStage ?? 'DRAFT'
|
|
26
26
|
if (conf.preview) {
|
|
27
|
-
|
|
27
|
+
headers['gcms-stage'] = stage
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
return
|
|
30
|
+
return { headers }
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
return { ...results, links: [...results.links, hygraphLink] }
|