@graphcommerce/graphcms-ui 8.1.0-canary.7 → 8.1.0-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,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.1.0-canary.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2223](https://github.com/graphcommerce-org/graphcommerce/pull/2223) [`0ccec63`](https://github.com/graphcommerce-org/graphcommerce/commit/0ccec630825d5fad398366beae90b3c90b2f84b8) - Added helper method to get Hygraph paths
8
+ ([@bramvanderholst](https://github.com/bramvanderholst))
9
+
10
+ ## 8.1.0-canary.8
11
+
3
12
  ## 8.1.0-canary.7
4
13
 
5
14
  ## 8.1.0-canary.6
@@ -0,0 +1,11 @@
1
+ query HygraphStaticPaths($pageSize: Int!, $skip: Int, $where: PageWhereInput) {
2
+ pages(first: $pageSize, skip: $skip, where: $where) {
3
+ url
4
+ }
5
+
6
+ pagesConnection {
7
+ aggregate {
8
+ count
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,43 @@
1
+ import { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
2
+ import type { PageWhereInput } from '@graphcommerce/graphql-mesh'
3
+ import { GetStaticPathsResult } from 'next'
4
+ import {
5
+ HygraphStaticPathsDocument,
6
+ HygraphStaticPathsQuery,
7
+ } from '../graphql/HygraphStaticPaths.gql'
8
+
9
+ type Return = GetStaticPathsResult<{ url: string }>
10
+
11
+ export async function getHygraphStaticPaths(
12
+ client: ApolloClient<NormalizedCacheObject>,
13
+ locale: string,
14
+ options: { pageSize?: number; filter?: PageWhereInput } = {},
15
+ ) {
16
+ const { pageSize = 100, filter = {} } = options
17
+ const query = client.query({
18
+ query: HygraphStaticPathsDocument,
19
+ variables: { pageSize, where: filter },
20
+ })
21
+ const pages: Promise<ApolloQueryResult<HygraphStaticPathsQuery>>[] = [query]
22
+
23
+ const { data } = await query
24
+ const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize) ?? 1
25
+
26
+ if (totalPages > 1) {
27
+ for (let i = 2; i <= totalPages; i++) {
28
+ pages.push(
29
+ client.query({
30
+ query: HygraphStaticPathsDocument,
31
+ variables: { pageSize, skip: pageSize * (i - 1), where: filter },
32
+ }),
33
+ )
34
+ }
35
+ }
36
+
37
+ const paths: Return['paths'] = (await Promise.all(pages))
38
+ .map((q) => q.data.pages)
39
+ .flat(1)
40
+ .map((page) => ({ params: page, locale }))
41
+
42
+ return paths
43
+ }
package/lib/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './hygraphPageContent'
2
+ export * from './getHygraphPaths'
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.1.0-canary.7",
5
+ "version": "8.1.0-canary.9",
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.1.0-canary.7",
16
- "@graphcommerce/graphql": "^8.1.0-canary.7",
17
- "@graphcommerce/image": "^8.1.0-canary.7",
18
- "@graphcommerce/next-ui": "^8.1.0-canary.7",
19
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.7",
20
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.7",
15
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
16
+ "@graphcommerce/graphql": "^8.1.0-canary.9",
17
+ "@graphcommerce/image": "^8.1.0-canary.9",
18
+ "@graphcommerce/next-ui": "^8.1.0-canary.9",
19
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
20
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
21
21
  "@mui/material": "^5.10.16",
22
22
  "next": "*",
23
23
  "react": "^18.2.0",