@graphcommerce/graphql 2.105.13 → 3.0.0

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,82 @@
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.
3
+ ## 3.0.0
5
4
 
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)
5
+ ### Major Changes
7
6
 
7
+ - [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
8
+ [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
9
+ Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
8
10
 
9
- ### Bug Fixes
11
+ ### Patch Changes
10
12
 
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))
13
+ - Updated dependencies
14
+ [[`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)]:
15
+ - @graphcommerce/graphql-codegen-near-operation-file@3.0.0
16
+ - @graphcommerce/graphql-codegen-relay-optimizer-plugin@3.0.0
12
17
 
18
+ All notable changes to this project will be documented in this file. See
19
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
13
20
 
21
+ ## [2.105.12](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.11...@graphcommerce/graphql@2.105.12) (2021-12-21)
14
22
 
23
+ ### Bug Fixes
15
24
 
25
+ - **graphql:** make sure we're passing the correct store code to the schema endpoint
26
+ ([39753f2](https://github.com/ho-nl/m2-pwa/commit/39753f2117ce7ba79dab035c4134e642829e7f18))
16
27
 
17
28
  ## [2.105.6](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.5...@graphcommerce/graphql@2.105.6) (2021-12-03)
18
29
 
19
-
20
30
  ### Bug Fixes
21
31
 
22
- * make the headerHeight properly configurable ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
23
-
24
-
25
-
26
-
32
+ - make the headerHeight properly configurable
33
+ ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
27
34
 
28
35
  # [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
36
 
30
-
31
37
  ### Features
32
38
 
33
- * **nextjs:** upgraded to nextjs 12 ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
34
-
35
-
36
-
37
-
39
+ - **nextjs:** upgraded to nextjs 12
40
+ ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
38
41
 
39
42
  # [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
43
 
41
-
42
44
  ### Features
43
45
 
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
-
46
+ - **graphql-mesh:** remove the api project and use a single project 🎉👩‍👩‍👦‍👦
47
+ ([ea4ad03](https://github.com/ho-nl/m2-pwa/commit/ea4ad0397d4ff289ef3b3253593fb0914c8c5246))
49
48
 
50
49
  ## [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
50
 
52
51
  **Note:** Version bump only for package @graphcommerce/graphql
53
52
 
54
-
55
-
56
-
57
-
58
53
  # 2.103.0 (2021-09-27)
59
54
 
60
-
61
55
  ### Bug Fixes
62
56
 
63
- * ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
64
-
57
+ - ignore md files from triggering version updates
58
+ ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
65
59
 
66
60
  ### Features
67
61
 
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
-
62
+ - **graphql:** introduced new graphql package that holds all generated files
63
+ ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
64
+ - **graphql:** introducing local schema migrations
65
+ ([e77ef8a](https://github.com/ho-nl/m2-pwa/commit/e77ef8ad4cd5723e2352dec937b45ee976929b24))
66
+ - next.js 11
67
+ ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
68
+ - **playwright:** added new playwright package to enable browser testing
69
+ ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
70
+ - renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of
71
+ [@reachdigital](https://github.com/reachdigital)
72
+ ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
73
+ - upgraded to nextjs 11
74
+ ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
75
75
 
76
76
  ### Reverts
77
77
 
78
- * Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
79
-
80
-
81
-
82
-
78
+ - Revert "chore: upgrade @apollo/client"
79
+ ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
83
80
 
84
81
  # Change Log
85
82
 
@@ -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
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,9 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql",
3
- "version": "2.105.13",
3
+ "version": "3.0.0",
4
4
  "sideEffects": false,
5
5
  "main": "index.ts",
6
6
  "prettier": "@graphcommerce/prettier-config-pwa",
7
- "browserslist": [
8
- "extends @graphcommerce/browserslist-config-pwa"
9
- ],
10
7
  "eslintConfig": {
11
8
  "extends": "@graphcommerce/eslint-config-pwa",
12
9
  "parserOptions": {
@@ -14,26 +11,25 @@
14
11
  }
15
12
  },
16
13
  "devDependencies": {
17
- "@graphcommerce/browserslist-config-pwa": "^3.0.3",
18
- "@graphcommerce/eslint-config-pwa": "^3.1.10",
19
- "@graphcommerce/prettier-config-pwa": "^3.0.5",
20
- "@graphcommerce/typescript-config-pwa": "^3.1.2",
21
- "@playwright/test": "^1.17.1"
14
+ "@graphcommerce/eslint-config-pwa": "^4.0.0",
15
+ "@graphcommerce/prettier-config-pwa": "^4.0.0",
16
+ "@graphcommerce/typescript-config-pwa": "^4.0.0",
17
+ "@playwright/test": "^1.18.1"
22
18
  },
23
19
  "dependencies": {
24
- "@apollo/client": "^3.5.6",
25
- "@graphcommerce/graphql-codegen-near-operation-file": "^2.103.19",
26
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "^2.102.20",
20
+ "@apollo/client": "^3.5.8",
21
+ "@graphcommerce/graphql-codegen-near-operation-file": "^3.0.0",
22
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "^3.0.0",
27
23
  "@graphql-codegen/add": "^3.1.1",
28
24
  "@graphql-codegen/fragment-matcher": "3.2.1",
29
25
  "@graphql-codegen/introspection": "2.1.1",
30
26
  "@graphql-codegen/schema-ast": "^2.4.1",
31
- "@graphql-codegen/typed-document-node": "^2.2.2",
32
- "@graphql-codegen/typescript": "^2.4.2",
33
- "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.9",
34
- "@graphql-codegen/typescript-document-nodes": "2.2.2",
35
- "@graphql-codegen/typescript-operations": "2.2.2",
36
- "graphql": "^16.2.0"
37
- },
38
- "gitHead": "bc5423d7547f8685db4cd8fc6d8f7a2a51ebed05"
27
+ "@graphql-codegen/typed-document-node": "^2.2.3",
28
+ "@graphql-codegen/typescript": "^2.4.3",
29
+ "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.10",
30
+ "@graphql-codegen/typescript-document-nodes": "2.2.3",
31
+ "@graphql-codegen/typescript-operations": "2.3.0",
32
+ "apollo3-cache-persist": "^0.14.0",
33
+ "graphql": "^16.3.0"
34
+ }
39
35
  }
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
+ }