@graphcommerce/graphql 2.105.11 → 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,74 +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.
5
-
6
- ## [2.105.6](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.105.5...@graphcommerce/graphql@2.105.6) (2021-12-03)
3
+ ## 3.0.0
7
4
 
5
+ ### Major Changes
8
6
 
9
- ### Bug Fixes
10
-
11
- * make the headerHeight properly configurable ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
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
12
10
 
11
+ ### Patch Changes
13
12
 
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
14
17
 
18
+ All notable changes to this project will be documented in this file. See
19
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
15
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)
16
22
 
17
- # [2.105.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.104.1...@graphcommerce/graphql@2.105.0) (2021-10-27)
23
+ ### Bug Fixes
18
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))
19
27
 
20
- ### Features
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)
21
29
 
22
- * **nextjs:** upgraded to nextjs 12 ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
30
+ ### Bug Fixes
23
31
 
32
+ - make the headerHeight properly configurable
33
+ ([c39c942](https://github.com/ho-nl/m2-pwa/commit/c39c942a62a9bb9687ea553be28e37fb49a6b065))
24
34
 
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)
25
36
 
37
+ ### Features
26
38
 
39
+ - **nextjs:** upgraded to nextjs 12
40
+ ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
27
41
 
28
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)
29
43
 
30
-
31
44
  ### Features
32
45
 
33
- * **graphql-mesh:** remove the api project and use a single project 🎉👩‍👩‍👦‍👦 ([ea4ad03](https://github.com/ho-nl/m2-pwa/commit/ea4ad0397d4ff289ef3b3253593fb0914c8c5246))
34
-
35
-
36
-
37
-
46
+ - **graphql-mesh:** remove the api project and use a single project 🎉👩‍👩‍👦‍👦
47
+ ([ea4ad03](https://github.com/ho-nl/m2-pwa/commit/ea4ad0397d4ff289ef3b3253593fb0914c8c5246))
38
48
 
39
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)
40
50
 
41
51
  **Note:** Version bump only for package @graphcommerce/graphql
42
52
 
43
-
44
-
45
-
46
-
47
53
  # 2.103.0 (2021-09-27)
48
54
 
49
-
50
55
  ### Bug Fixes
51
56
 
52
- * ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
53
-
57
+ - ignore md files from triggering version updates
58
+ ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
54
59
 
55
60
  ### Features
56
61
 
57
- * **graphql:** introduced new graphql package that holds all generated files ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
58
- * **graphql:** introducing local schema migrations ([e77ef8a](https://github.com/ho-nl/m2-pwa/commit/e77ef8ad4cd5723e2352dec937b45ee976929b24))
59
- * next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
60
- * **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
61
- * 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))
62
- * upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
63
-
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))
64
75
 
65
76
  ### Reverts
66
77
 
67
- * Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
68
-
69
-
70
-
71
-
78
+ - Revert "chore: upgrade @apollo/client"
79
+ ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
72
80
 
73
81
  # Change Log
74
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
@@ -21,6 +21,10 @@ interface TracingFormat {
21
21
  }
22
22
  }
23
23
 
24
+ /**
25
+ * This doesn't work with the current implementation of the Apollo client. We're using SchemaLink
26
+ * which doesn't support additional links.
27
+ */
24
28
  export const measurePerformanceLink = new ApolloLink((operation, forward) => {
25
29
  if (typeof global.window !== 'undefined') {
26
30
  return forward(operation)
@@ -34,7 +38,7 @@ export const measurePerformanceLink = new ApolloLink((operation, forward) => {
34
38
  let vars =
35
39
  Object.keys(operation.variables).length > 0 ? `(${JSON.stringify(operation.variables)})` : ''
36
40
  if (vars.length > 100) {
37
- vars = `${vars.substr(0, 100)}…`
41
+ vars = `${vars.substring(0, 100)}…`
38
42
  }
39
43
 
40
44
  if (data.extensions?.tracing && time > slowOperationThreshold) {
@@ -42,7 +46,7 @@ export const measurePerformanceLink = new ApolloLink((operation, forward) => {
42
46
 
43
47
  const duration = Math.round(tracing.duration / (1000 * 1000))
44
48
 
45
- console.group(`[slow] ${operation.operationName}${vars}`)
49
+ console.group(`GraphQL slow query/mutation '${operation.operationName}'${vars}`)
46
50
  console.info(`operations ${duration}ms, mesh: ${time - duration}ms`)
47
51
 
48
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,9 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql",
3
- "version": "2.105.11",
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.9",
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.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": "7cfbdb5a042e271252c8b9729393e084002a321e"
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",
23
+ "@graphql-codegen/add": "^3.1.1",
24
+ "@graphql-codegen/fragment-matcher": "3.2.1",
25
+ "@graphql-codegen/introspection": "2.1.1",
26
+ "@graphql-codegen/schema-ast": "^2.4.1",
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
+ }