@graphcommerce/graphql 2.105.2 → 2.105.3

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.
Files changed (3) hide show
  1. package/errorLink.ts +29 -0
  2. package/index.ts +1 -0
  3. package/package.json +2 -2
package/errorLink.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { onError } from '@apollo/client/link/error'
2
+
3
+ export const errorLink = onError(({ graphQLErrors, networkError, operation }) => {
4
+ if (process.env.NODE_ENV !== 'production') {
5
+ if (graphQLErrors)
6
+ console.error(
7
+ `[GraphQL errors]: ${graphQLErrors
8
+ .map(({ message, path }) => `${message} ${path?.join(',')}`)
9
+ .join(', ')}`,
10
+ )
11
+
12
+ if (networkError)
13
+ console.error(`[Graphql error]: ${networkError}`)
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
16
+ ;(async () => {
17
+ const graphql = await import('graphql')
18
+
19
+ const gqlString = graphql
20
+ .print(operation.query)
21
+ .toString()
22
+ .replace(/(\r\n|\n|\r)/gm, ' ')
23
+ .replace(/\s\s+/g, ' ')
24
+
25
+ console.error(`[GraphQL operation]: ${gqlString}`)
26
+ console.error(`[GraphQL variables]: ${JSON.stringify(operation.variables)}`)
27
+ })()
28
+ }
29
+ })
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './measurePerformanceLink'
2
+ export * from './errorLink'
2
3
 
3
4
  export * from './generated/types'
4
5
  export { default as fragments } from './generated/fragments.json'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql",
3
- "version": "2.105.2",
3
+ "version": "2.105.3",
4
4
  "sideEffects": false,
5
5
  "main": "index.ts",
6
6
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -27,5 +27,5 @@
27
27
  "react": "^17.0.2",
28
28
  "react-dom": "^17.0.2"
29
29
  },
30
- "gitHead": "b6321b8f479a0ef6e4b1b543702158d964bbeac6"
30
+ "gitHead": "7aca802dd74632aa2f474eae2d93bd563490fd90"
31
31
  }