@graphcommerce/magento-graphql 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 +8 -0
- package/graphqlErrorByCategory.ts +20 -15
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ErrorLike } from '@apollo/client'
|
|
2
|
+
import { CombinedGraphQLErrors } from '@apollo/client/errors'
|
|
2
3
|
import type { GraphQLFormattedError } from 'graphql'
|
|
3
4
|
|
|
4
5
|
export type ErrorCategory =
|
|
@@ -11,7 +12,7 @@ export type ErrorCategory =
|
|
|
11
12
|
|
|
12
13
|
export type GraphQLErrorByCategoryProps = {
|
|
13
14
|
category: ErrorCategory
|
|
14
|
-
error?:
|
|
15
|
+
error?: ErrorLike | null
|
|
15
16
|
extract?: true
|
|
16
17
|
mask?: string
|
|
17
18
|
}
|
|
@@ -28,30 +29,34 @@ export type GraphQLErrorByCategoryPropsNoExtract = Omit<GraphQLErrorByCategoryPr
|
|
|
28
29
|
*/
|
|
29
30
|
export function graphqlErrorByCategory(
|
|
30
31
|
props: GraphQLErrorByCategoryPropsNoExtract,
|
|
31
|
-
): [
|
|
32
|
+
): [ErrorLike, GraphQLFormattedError | undefined]
|
|
32
33
|
export function graphqlErrorByCategory(
|
|
33
34
|
props: GraphQLErrorByCategoryProps,
|
|
34
|
-
): [
|
|
35
|
+
): [ErrorLike | undefined, GraphQLFormattedError | undefined]
|
|
35
36
|
export function graphqlErrorByCategory(
|
|
36
37
|
props: GraphQLErrorByCategoryProps | GraphQLErrorByCategoryPropsNoExtract,
|
|
37
|
-
): [
|
|
38
|
+
): [ErrorLike | undefined, GraphQLFormattedError | undefined] {
|
|
38
39
|
const { category, error, extract = true, mask } = props
|
|
39
40
|
|
|
40
41
|
if (!error) return [undefined, undefined]
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
// Check if this is a CombinedGraphQLErrors
|
|
44
|
+
if (!CombinedGraphQLErrors.is(error)) {
|
|
45
|
+
// Not a GraphQL error, return as-is
|
|
46
|
+
return [error, undefined]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const filteredErrors = error.errors.filter(
|
|
50
|
+
(err) => !extract || err?.extensions?.category !== category,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const newError =
|
|
54
|
+
filteredErrors.length > 0 ? new CombinedGraphQLErrors({ errors: filteredErrors }) : undefined
|
|
48
55
|
|
|
49
|
-
let graphqlError = error.
|
|
56
|
+
let graphqlError = error.errors.find((err) => err?.extensions?.category === category)
|
|
50
57
|
if (mask && graphqlError) {
|
|
51
58
|
graphqlError = { ...graphqlError, message: mask }
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
return newError
|
|
55
|
-
? [undefined, graphqlError]
|
|
56
|
-
: [newError, graphqlError]
|
|
61
|
+
return [newError, graphqlError]
|
|
57
62
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-graphql",
|
|
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
|
"main": "index.ts",
|
|
8
8
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"./mesh/magentoOrderItemResolvers.ts": "./mesh/magentoOrderItemResolvers.ts"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.
|
|
29
|
-
"@graphcommerce/graphql": "^10.0.0-canary.
|
|
30
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.
|
|
31
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.
|
|
28
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.0-canary.72",
|
|
29
|
+
"@graphcommerce/graphql": "^10.0.0-canary.72",
|
|
30
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.0-canary.72",
|
|
31
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.0-canary.72",
|
|
32
32
|
"graphql": "^16.0.0",
|
|
33
33
|
"next": "*",
|
|
34
34
|
"react": "^19.2.0",
|