@graphcommerce/graphql-mesh 9.0.0-canary.65 → 9.0.0-canary.67
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 +8 -0
- package/index.ts +1 -0
- package/package.json +4 -4
- package/utils/traverseSelectionSet.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.0.0-canary.67
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2336](https://github.com/graphcommerce-org/graphcommerce/pull/2336) [`214bc56`](https://github.com/graphcommerce-org/graphcommerce/commit/214bc56950f397727d2c5417741dc62419080dfa) - Added traverseSelectionSet utility function to extract a child selection set from the parent. ([@Renzovh](https://github.com/Renzovh))
|
|
8
|
+
|
|
9
|
+
## 9.0.0-canary.66
|
|
10
|
+
|
|
3
11
|
## 9.0.0-canary.65
|
|
4
12
|
|
|
5
13
|
## 9.0.0-canary.64
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/graphql-mesh",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.0-canary.
|
|
5
|
+
"version": "9.0.0-canary.67",
|
|
6
6
|
"main": "index.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@graphql-mesh/apollo-link": "latest",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@apollo/client": "^3",
|
|
38
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.
|
|
39
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.
|
|
40
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.
|
|
38
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.67",
|
|
39
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.67",
|
|
40
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.67",
|
|
41
41
|
"graphql": "^16.7.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Kind, SelectionNode, SelectionSetNode } from 'graphql'
|
|
2
|
+
import type { Path } from 'react-hook-form'
|
|
3
|
+
|
|
4
|
+
function isNumeric(n: string) {
|
|
5
|
+
return !Number.isNaN(parseFloat(n))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function traverseSelectionSet<Q>(incomingSelectionSet: SelectionSetNode, path: Path<Q>) {
|
|
9
|
+
const pathArray = path.split(/[,[\].]+?/)
|
|
10
|
+
let selectionSet = incomingSelectionSet
|
|
11
|
+
let pathIndex = 0
|
|
12
|
+
|
|
13
|
+
while (pathIndex < pathArray.length) {
|
|
14
|
+
let currentValue = pathArray[pathIndex]
|
|
15
|
+
const isNegation = currentValue.startsWith('!')
|
|
16
|
+
currentValue = isNegation ? currentValue.slice(1) : currentValue
|
|
17
|
+
|
|
18
|
+
if (!isNumeric(currentValue)) {
|
|
19
|
+
const newSelections: SelectionNode[] = []
|
|
20
|
+
|
|
21
|
+
for (const selection of selectionSet.selections) {
|
|
22
|
+
if (selection.kind === Kind.FIELD) {
|
|
23
|
+
if (!isNegation && selection.name.value === currentValue) {
|
|
24
|
+
newSelections.push(...(selection.selectionSet?.selections ?? []))
|
|
25
|
+
}
|
|
26
|
+
if (isNegation && selection.name.value !== currentValue) {
|
|
27
|
+
newSelections.push(...(selection.selectionSet?.selections ?? []))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
selectionSet = {
|
|
33
|
+
kind: Kind.SELECTION_SET,
|
|
34
|
+
selections: newSelections,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
pathIndex++
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return selectionSet
|
|
42
|
+
}
|