@graphcommerce/graphql 2.105.12 → 3.0.1

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,85 +1,94 @@
1
1
  # Change Log
2
2
 
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [2.105.12](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.11...@graphcommerce/graphql@2.105.12) (2021-12-21)
3
+ ## 3.0.1
7
4
 
5
+ ### Patch Changes
8
6
 
9
- ### Bug Fixes
7
+ - [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)
8
+ Thanks [@paales](https://github.com/paales)! - Added homepage and repository package.json files,
9
+ so that the packages link to back to the website and repository
10
+ - Updated dependencies
11
+ [[`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)]:
12
+ - @graphcommerce/graphql-codegen-near-operation-file@3.0.1
13
+ - @graphcommerce/graphql-codegen-relay-optimizer-plugin@3.0.1
10
14
 
11
- * **graphql:** make sure we're passing the correct store code to the schema endpoint ([39753f2](https://github.com/ho-nl/m2-pwa/commit/39753f2117ce7ba79dab035c4134e642829e7f18))
15
+ ## 3.0.0
12
16
 
17
+ ### Major Changes
13
18
 
19
+ - [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
20
+ [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
21
+ Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
14
22
 
23
+ ### Patch Changes
15
24
 
25
+ - Updated dependencies
26
+ [[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)]:
27
+ - @graphcommerce/graphql-codegen-near-operation-file@3.0.0
28
+ - @graphcommerce/graphql-codegen-relay-optimizer-plugin@3.0.0
16
29
 
17
- ## [2.105.6](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.5...@graphcommerce/graphql@2.105.6) (2021-12-03)
30
+ All notable changes to this project will be documented in this file. See
31
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
18
32
 
33
+ ## [2.105.12](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.11...@graphcommerce/graphql@2.105.12) (2021-12-21)
19
34
 
20
35
  ### Bug Fixes
21
36
 
22
- * make the headerHeight properly configurable ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
23
-
37
+ - **graphql:** make sure we're passing the correct store code to the schema endpoint
38
+ ([39753f2](https://github.com/ho-nl/m2-pwa/commit/39753f2117ce7ba79dab035c4134e642829e7f18))
24
39
 
40
+ ## [2.105.6](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.5...@graphcommerce/graphql@2.105.6) (2021-12-03)
25
41
 
42
+ ### Bug Fixes
26
43
 
44
+ - make the headerHeight properly configurable
45
+ ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
27
46
 
28
47
  # [2.105.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.104.1...@graphcommerce/graphql@2.105.0) (2021-10-27)
29
48
 
30
-
31
49
  ### Features
32
50
 
33
- * **nextjs:** upgraded to nextjs 12 ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
34
-
35
-
36
-
37
-
51
+ - **nextjs:** upgraded to nextjs 12
52
+ ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
38
53
 
39
54
  # [2.104.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.103.8...@graphcommerce/graphql@2.104.0) (2021-10-21)
40
55
 
41
-
42
56
  ### Features
43
57
 
44
- * **graphql-mesh:** remove the api project and use a single project 🎉👩‍👩‍👦‍👦 ([ea4ad03](https://github.com/ho-nl/m2-pwa/commit/ea4ad0397d4ff289ef3b3253593fb0914c8c5246))
45
-
46
-
47
-
48
-
58
+ - **graphql-mesh:** remove the api project and use a single project 🎉👩‍👩‍👦‍👦
59
+ ([ea4ad03](https://github.com/ho-nl/m2-pwa/commit/ea4ad0397d4ff289ef3b3253593fb0914c8c5246))
49
60
 
50
61
  ## [2.103.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.103.0...@graphcommerce/graphql@2.103.1) (2021-09-27)
51
62
 
52
63
  **Note:** Version bump only for package @graphcommerce/graphql
53
64
 
54
-
55
-
56
-
57
-
58
65
  # 2.103.0 (2021-09-27)
59
66
 
60
-
61
67
  ### Bug Fixes
62
68
 
63
- * ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
64
-
69
+ - ignore md files from triggering version updates
70
+ ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
65
71
 
66
72
  ### Features
67
73
 
68
- * **graphql:** introduced new graphql package that holds all generated files ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
69
- * **graphql:** introducing local schema migrations ([e77ef8a](https://github.com/ho-nl/m2-pwa/commit/e77ef8ad4cd5723e2352dec937b45ee976929b24))
70
- * next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
71
- * **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
72
- * renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
73
- * upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
74
-
74
+ - **graphql:** introduced new graphql package that holds all generated files
75
+ ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
76
+ - **graphql:** introducing local schema migrations
77
+ ([e77ef8a](https://github.com/ho-nl/m2-pwa/commit/e77ef8ad4cd5723e2352dec937b45ee976929b24))
78
+ - next.js 11
79
+ ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
80
+ - **playwright:** added new playwright package to enable browser testing
81
+ ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
82
+ - renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of
83
+ [@reachdigital](https://github.com/reachdigital)
84
+ ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
85
+ - upgraded to nextjs 11
86
+ ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
75
87
 
76
88
  ### Reverts
77
89
 
78
- * Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
79
-
80
-
81
-
82
-
90
+ - Revert "chore: upgrade @apollo/client"
91
+ ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
83
92
 
84
93
  # Change Log
85
94
 
@@ -1,13 +1,13 @@
1
1
  /* eslint-disable no-empty-pattern */
2
+ import { getOperationName } from '@graphcommerce/graphql'
3
+ import { test as base, Page } from '@playwright/test'
2
4
  import {
3
5
  ApolloClient,
4
6
  FetchResult,
5
7
  InMemoryCache,
6
8
  NormalizedCacheObject,
7
9
  TypedDocumentNode,
8
- } from '@apollo/client'
9
- import { getOperationName } from '@apollo/client/utilities'
10
- import { test as base, Page } from '@playwright/test'
10
+ } from '../apollo'
11
11
 
12
12
  type ApolloClientTest = {
13
13
  apolloClient: ApolloClient<NormalizedCacheObject>
package/apollo.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { cloneDeep, mergeDeep } from '@apollo/client/utilities'
2
+
3
+ export * from '@apollo/client'
4
+ export * from '@apollo/client/link/schema'
5
+ export * from '@apollo/client/link/context'
6
+ export { getOperationName } from '@apollo/client/utilities'
@@ -0,0 +1,67 @@
1
+ import { LocalStorageWrapper, CachePersistor } from 'apollo3-cache-persist'
2
+ import { mergeDeep, ApolloCache, ApolloClient, NormalizedCacheObject } from './apollo'
3
+ import type { TypedTypePolicies } from './generated/types'
4
+ import { MigrateCache, migrateCacheHandler } from './migrateCache'
5
+ import { getTypePoliciesVersion } from './typePolicies'
6
+
7
+ const APOLLO_CACHE_PERSIST = 'apollo-cache-persist'
8
+ const APOLLO_CACHE_VERSION = 'apollo-cache-version'
9
+
10
+ /** Revives the cache from the localStorage if it is available. */
11
+ export function createCacheReviver(
12
+ client: ApolloClient<NormalizedCacheObject>,
13
+ createCache: () => ApolloCache<NormalizedCacheObject>,
14
+ policies: TypedTypePolicies[],
15
+ migrations: MigrateCache[],
16
+ incommingState: NormalizedCacheObject = {},
17
+ ) {
18
+ let state = incommingState
19
+ const typePoliciesVersion = getTypePoliciesVersion(policies)
20
+
21
+ if (typeof window !== 'undefined') {
22
+ try {
23
+ const { cache } = client
24
+ const persistor = new CachePersistor({
25
+ cache,
26
+ storage: new LocalStorageWrapper(window.localStorage),
27
+ maxSize: false,
28
+ key: APOLLO_CACHE_PERSIST,
29
+ })
30
+
31
+ const storedState = window.localStorage[APOLLO_CACHE_PERSIST] as string | undefined
32
+ const currentVersion = window.localStorage[APOLLO_CACHE_VERSION] as string | undefined
33
+
34
+ if (currentVersion === typePoliciesVersion && storedState) {
35
+ state = mergeDeep(JSON.parse(storedState), incommingState)
36
+ } else if (storedState) {
37
+ console.info(
38
+ '[@graphcommerce/graphql] migrating apollo cache, detected a typePolicy change',
39
+ )
40
+ try {
41
+ const oldCache = createCache()
42
+ oldCache.restore(JSON.parse(storedState) as NormalizedCacheObject)
43
+
44
+ // Run the migration
45
+ migrateCacheHandler(oldCache, cache, migrations)
46
+
47
+ state = mergeDeep(cache.extract(), incommingState)
48
+ console.info('migration complete')
49
+ } catch (e) {
50
+ console.info('migration error (starting with a clean state):', e)
51
+
52
+ // couldn't be upgraded
53
+ state = incommingState
54
+ }
55
+ }
56
+ window.localStorage[APOLLO_CACHE_VERSION] = typePoliciesVersion
57
+ window.localStorage[APOLLO_CACHE_PERSIST] = JSON.stringify(state)
58
+
59
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
60
+ persistor.restore()
61
+ } catch (e) {
62
+ console.error(e)
63
+ }
64
+ }
65
+
66
+ if (state) client.cache.restore(state)
67
+ }
package/index.ts CHANGED
@@ -1,8 +1,13 @@
1
+ export * from './generated/types'
2
+
1
3
  export * from './measurePerformanceLink'
2
4
  export * from './errorLink'
3
5
 
4
- export * from './generated/types'
5
6
  export { default as fragments } from './generated/fragments.json'
6
7
 
7
8
  export * from './migrateCache'
8
9
  export * from './typePolicies'
10
+ export * from './createCacheReviver'
11
+
12
+ export * from './apollo'
13
+ export * from './types'
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-console */
2
- import { ApolloLink } from '@apollo/client/core'
2
+ import { ApolloLink } from '@apollo/client'
3
3
 
4
4
  const slowOperationThreshold = 1000
5
5
  const slowResolverThreshold = 300
@@ -38,7 +38,7 @@ export const measurePerformanceLink = new ApolloLink((operation, forward) => {
38
38
  let vars =
39
39
  Object.keys(operation.variables).length > 0 ? `(${JSON.stringify(operation.variables)})` : ''
40
40
  if (vars.length > 100) {
41
- vars = `${vars.substr(0, 100)}…`
41
+ vars = `${vars.substring(0, 100)}…`
42
42
  }
43
43
 
44
44
  if (data.extensions?.tracing && time > slowOperationThreshold) {
@@ -46,7 +46,7 @@ export const measurePerformanceLink = new ApolloLink((operation, forward) => {
46
46
 
47
47
  const duration = Math.round(tracing.duration / (1000 * 1000))
48
48
 
49
- console.group(`[slow] ${operation.operationName}${vars}`)
49
+ console.group(`GraphQL slow query/mutation '${operation.operationName}'${vars}`)
50
50
  console.info(`operations ${duration}ms, mesh: ${time - duration}ms`)
51
51
 
52
52
  tracing.execution.resolvers
package/migrateCache.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ApolloCache, NormalizedCacheObject } from '@apollo/client'
1
+ import { ApolloCache, NormalizedCacheObject } from './apollo'
2
2
 
3
3
  export type MigrateCache = (
4
4
  oldCache: ApolloCache<NormalizedCacheObject>,
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql",
3
- "version": "2.105.12",
3
+ "homepage": "https://www.graphcommerce.org/",
4
+ "repository": "github:graphcommerce-org/graphcommerce",
5
+ "version": "3.0.1",
4
6
  "sideEffects": false,
5
7
  "main": "index.ts",
6
8
  "prettier": "@graphcommerce/prettier-config-pwa",
7
- "browserslist": [
8
- "extends @graphcommerce/browserslist-config-pwa"
9
- ],
10
9
  "eslintConfig": {
11
10
  "extends": "@graphcommerce/eslint-config-pwa",
12
11
  "parserOptions": {
@@ -14,26 +13,25 @@
14
13
  }
15
14
  },
16
15
  "devDependencies": {
17
- "@graphcommerce/browserslist-config-pwa": "^3.0.3",
18
- "@graphcommerce/eslint-config-pwa": "^3.1.9",
19
- "@graphcommerce/prettier-config-pwa": "^3.0.5",
20
- "@graphcommerce/typescript-config-pwa": "^3.1.2",
21
- "@playwright/test": "^1.17.1"
16
+ "@graphcommerce/eslint-config-pwa": "^4.0.1",
17
+ "@graphcommerce/prettier-config-pwa": "^4.0.1",
18
+ "@graphcommerce/typescript-config-pwa": "^4.0.1",
19
+ "@playwright/test": "^1.18.1"
22
20
  },
23
21
  "dependencies": {
24
- "@apollo/client": "^3.5.6",
25
- "@graphcommerce/graphql-codegen-near-operation-file": "^2.103.18",
26
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "^2.102.19",
27
- "@graphql-codegen/add": "^3.1.0",
28
- "@graphql-codegen/fragment-matcher": "3.2.0",
29
- "@graphql-codegen/introspection": "2.1.0",
30
- "@graphql-codegen/schema-ast": "^2.4.0",
31
- "@graphql-codegen/typed-document-node": "^2.2.1",
32
- "@graphql-codegen/typescript": "^2.4.1",
33
- "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.8",
34
- "@graphql-codegen/typescript-document-nodes": "2.2.1",
35
- "@graphql-codegen/typescript-operations": "2.2.1",
36
- "graphql": "^16.2.0"
37
- },
38
- "gitHead": "09aca3fbe0a5dc006b33fc8dee349c81bcbe0cb8"
22
+ "@apollo/client": "^3.5.8",
23
+ "@graphcommerce/graphql-codegen-near-operation-file": "^3.0.1",
24
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "^3.0.1",
25
+ "@graphql-codegen/add": "^3.1.1",
26
+ "@graphql-codegen/fragment-matcher": "3.2.1",
27
+ "@graphql-codegen/introspection": "2.1.1",
28
+ "@graphql-codegen/schema-ast": "^2.4.1",
29
+ "@graphql-codegen/typed-document-node": "^2.2.3",
30
+ "@graphql-codegen/typescript": "^2.4.3",
31
+ "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.10",
32
+ "@graphql-codegen/typescript-document-nodes": "2.2.3",
33
+ "@graphql-codegen/typescript-operations": "2.3.0",
34
+ "apollo3-cache-persist": "^0.14.0",
35
+ "graphql": "^16.3.0"
36
+ }
39
37
  }
package/typePolicies.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { mergeDeep } from '@apollo/client/utilities'
2
- import { TypedTypePolicies } from './generated/types'
1
+ import { mergeDeep } from './apollo'
2
+ import type { TypedTypePolicies } from './generated/types'
3
3
 
4
4
  export const mergeTypePolicies = (policies: TypedTypePolicies[]): TypedTypePolicies =>
5
5
  mergeDeep(...policies)
package/types.ts ADDED
@@ -0,0 +1,16 @@
1
+ /** The GraphQL API will return fields as null if they are not required. */
2
+ export type ObjectNonNullable<T> = {
3
+ [P in keyof T]: NonNullable<T[P]>
4
+ }
5
+
6
+ /** Typescript will return null for fields */
7
+ export function removeNull<T extends Record<string, unknown>>(object: T): ObjectNonNullable<T> {
8
+ // eslint-disable-next-line no-restricted-syntax
9
+
10
+ const myobj = { ...object } as ObjectNonNullable<T>
11
+ Object.keys(myobj).forEach((key: keyof T) => {
12
+ if (myobj[key] === null) myobj[key] = undefined as NonNullable<T[keyof T]>
13
+ })
14
+
15
+ return myobj
16
+ }