@graphcommerce/hygraph-dynamic-rows 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
  # @graphcommerce/hygraph-dynamic-rows
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,5 @@
1
- query AllDynamicRows {
2
- dynamicRows(first: 1000) {
1
+ query AllDynamicRows($first: Int = 100, $skip: Int) {
2
+ dynamicRows(first: $first, skip: $skip) {
3
3
  id
4
4
  conditions {
5
5
  __typename
@@ -8,4 +8,10 @@ query AllDynamicRows {
8
8
  ...ConditionAnd
9
9
  }
10
10
  }
11
+
12
+ pagesConnection {
13
+ aggregate {
14
+ count
15
+ }
16
+ }
11
17
  }
@@ -0,0 +1,42 @@
1
+ import type { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
2
+ import { AllDynamicRowsDocument, AllDynamicRowsQuery } from '../graphql'
3
+
4
+ type DynamicRows = AllDynamicRowsQuery['dynamicRows']
5
+
6
+ export async function getAllHygraphDynamicRows(
7
+ client: ApolloClient<NormalizedCacheObject>,
8
+ options: { pageSize?: number } = {},
9
+ ) {
10
+ const { pageSize = 100 } = options
11
+ const query = client.query({
12
+ query: AllDynamicRowsDocument,
13
+ variables: { first: pageSize },
14
+ fetchPolicy: process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined,
15
+ })
16
+
17
+ const pages: Promise<ApolloQueryResult<AllDynamicRowsQuery>>[] = [query]
18
+
19
+ const { data } = await query
20
+ const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize) ?? 1
21
+ if (totalPages > 1) {
22
+ for (let i = 2; i <= totalPages; i++) {
23
+ pages.push(
24
+ client.query({
25
+ query: AllDynamicRowsDocument,
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 dynamicRows: DynamicRows = (await Promise.all(pages))
34
+ .map((q) => q.data.dynamicRows)
35
+ .flat(1)
36
+ .map((row) => ({
37
+ id: row.id,
38
+ conditions: row.conditions,
39
+ }))
40
+
41
+ return dynamicRows
42
+ }
@@ -1,13 +1,13 @@
1
1
  import { HygraphPagesQuery } from '@graphcommerce/graphcms-ui'
2
2
  import { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql'
3
3
  import {
4
- AllDynamicRowsDocument,
5
4
  ConditionTextFragment,
6
5
  ConditionNumberFragment,
7
6
  ConditionOrFragment,
8
7
  ConditionAndFragment,
9
8
  DynamicRowsDocument,
10
9
  } from '../graphql'
10
+ import { getAllHygraphDynamicRows } from './getAllHygraphDynamicRows'
11
11
 
12
12
  /**
13
13
  * This generally works the same way as lodash get, however, when encountering an array it will
@@ -97,17 +97,16 @@ export async function hygraphDynamicRows(
97
97
  const alwaysCache = process.env.NODE_ENV !== 'development' ? 'cache-first' : undefined
98
98
  const fetchPolicy = cached ? alwaysCache : undefined
99
99
 
100
- const allRoutes = await client.query({ query: AllDynamicRowsDocument, fetchPolicy: alwaysCache })
100
+ const allRoutes = await getAllHygraphDynamicRows(client)
101
101
 
102
102
  // Get the required rowIds from the conditions
103
103
  const properties = { ...(await additionalProperties), url }
104
104
 
105
- const rowIds = allRoutes.data.dynamicRows
105
+ const rowIds = allRoutes
106
106
  .filter((availableDynamicRow) =>
107
107
  availableDynamicRow.conditions.some((condition) => matchCondition(condition, properties)),
108
108
  )
109
109
  .map((row) => row.id)
110
-
111
110
  const dynamicRows =
112
111
  rowIds.length !== 0
113
112
  ? client.query({ query: DynamicRowsDocument, variables: { rowIds }, fetchPolicy })
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/hygraph-dynamic-rows",
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,13 +12,13 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.0.5-canary.8",
16
- "@graphcommerce/graphcms-ui": "^8.0.5-canary.8",
17
- "@graphcommerce/graphql": "^8.0.5-canary.8",
18
- "@graphcommerce/image": "^8.0.5-canary.8",
19
- "@graphcommerce/next-ui": "^8.0.5-canary.8",
20
- "@graphcommerce/prettier-config-pwa": "^8.0.5-canary.8",
21
- "@graphcommerce/typescript-config-pwa": "^8.0.5-canary.8",
15
+ "@graphcommerce/eslint-config-pwa": "^8.0.5",
16
+ "@graphcommerce/graphcms-ui": "^8.0.5",
17
+ "@graphcommerce/graphql": "^8.0.5",
18
+ "@graphcommerce/image": "^8.0.5",
19
+ "@graphcommerce/next-ui": "^8.0.5",
20
+ "@graphcommerce/prettier-config-pwa": "^8.0.5",
21
+ "@graphcommerce/typescript-config-pwa": "^8.0.5",
22
22
  "@mui/material": "^5.10.16",
23
23
  "next": "*",
24
24
  "react": "^18.2.0",