@graphcommerce/graphcms-ui 8.0.5-canary.8 → 8.0.5

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,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination.
8
+ ([@Jessevdpoel](https://github.com/Jessevdpoel))
9
+
10
+ ## 8.0.5-canary.10
11
+
12
+ ## 8.0.5-canary.9
13
+
14
+ ### Patch Changes
15
+
16
+ - [#2238](https://github.com/graphcommerce-org/graphcommerce/pull/2238) [`db86432`](https://github.com/graphcommerce-org/graphcommerce/commit/db864324277fd5fb680c66eaa87d211cd7be4905) - Changed query limit to 100 from a 1000 on HygraphAllPages and AllDynamicRows query and added pagination.
17
+ ([@Jessevdpoel](https://github.com/Jessevdpoel))
18
+
3
19
  ## 8.0.5-canary.8
4
20
 
5
21
  ## 8.0.5-canary.7
@@ -1,5 +1,11 @@
1
- query HygraphAllPages($first: Int = 1000) {
2
- pages(first: $first) {
1
+ query HygraphAllPages($first: Int = 100, $skip: Int) {
2
+ pages(first: $first, skip: $skip) {
3
3
  url
4
4
  }
5
+
6
+ pagesConnection {
7
+ aggregate {
8
+ count
9
+ }
10
+ }
5
11
  }
@@ -0,0 +1,41 @@
1
+ import type { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
2
+ import { HygraphAllPagesDocument, HygraphAllPagesQuery } from '../graphql'
3
+
4
+ type Urls = { url: string }
5
+
6
+ export async function getAllHygraphPages(
7
+ client: ApolloClient<NormalizedCacheObject>,
8
+ options: { pageSize?: number } = {},
9
+ ) {
10
+ const { pageSize = 100 } = options
11
+ const query = client.query({
12
+ query: HygraphAllPagesDocument,
13
+ variables: { first: pageSize },
14
+ fetchPolicy: process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined,
15
+ })
16
+ const pages: Promise<ApolloQueryResult<HygraphAllPagesQuery>>[] = [query]
17
+
18
+ const { data } = await query
19
+ const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize) ?? 1
20
+
21
+ if (totalPages > 1) {
22
+ for (let i = 2; i <= totalPages; i++) {
23
+ pages.push(
24
+ client.query({
25
+ query: HygraphAllPagesDocument,
26
+ variables: { first: pageSize, skip: pageSize * (i - 1) },
27
+ fetchPolicy: process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined,
28
+ }),
29
+ )
30
+ }
31
+ }
32
+
33
+ const paths: Urls[] = (await Promise.all(pages))
34
+ .map((q) => q.data.pages)
35
+ .flat(1)
36
+ .map((page) => ({
37
+ url: page.url,
38
+ }))
39
+
40
+ return paths
41
+ }
@@ -1,5 +1,6 @@
1
1
  import { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql'
2
- import { HygraphAllPagesDocument, HygraphPagesQuery, HygraphPagesDocument } from '../graphql'
2
+ import { HygraphPagesQuery, HygraphPagesDocument } from '../graphql'
3
+ import { getAllHygraphPages } from './getAllHygraphPages'
3
4
 
4
5
  /**
5
6
  * Fetch the page content for the given urls.
@@ -28,10 +29,9 @@ async function pageContent(
28
29
  const alwaysCache = process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined
29
30
  const fetchPolicy = cached ? alwaysCache : undefined
30
31
 
31
- const allRoutes = await client.query({ query: HygraphAllPagesDocument, fetchPolicy: alwaysCache })
32
-
32
+ const allRoutes = await getAllHygraphPages(client)
33
33
  // Only do the query when there the page is found in the allRoutes
34
- const found = allRoutes.data.pages.some((page) => page.url === url)
34
+ const found = allRoutes.some((page) => page.url === url)
35
35
 
36
36
  return found
37
37
  ? client.query({ query: HygraphPagesDocument, variables: { url }, fetchPolicy })
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphcms-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.0.5-canary.8",
5
+ "version": "8.0.5",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,12 +12,12 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.0.5-canary.8",
16
- "@graphcommerce/graphql": "^8.0.5-canary.8",
17
- "@graphcommerce/image": "^8.0.5-canary.8",
18
- "@graphcommerce/next-ui": "^8.0.5-canary.8",
19
- "@graphcommerce/prettier-config-pwa": "^8.0.5-canary.8",
20
- "@graphcommerce/typescript-config-pwa": "^8.0.5-canary.8",
15
+ "@graphcommerce/eslint-config-pwa": "^8.0.5",
16
+ "@graphcommerce/graphql": "^8.0.5",
17
+ "@graphcommerce/image": "^8.0.5",
18
+ "@graphcommerce/next-ui": "^8.0.5",
19
+ "@graphcommerce/prettier-config-pwa": "^8.0.5",
20
+ "@graphcommerce/typescript-config-pwa": "^8.0.5",
21
21
  "@mui/material": "^5.10.16",
22
22
  "next": "*",
23
23
  "react": "^18.2.0",